In this tutorial, we will explain how to create a batch file to delete folder automatically using the CMD (command line). We will continue with the series of tutorials regarding the usage of batch file. The command will erase all files and subfolders in the specified folder.
This batch file can be very useful if needed to delete large folders. Using the command line can be over 20 times faster than going through Windows Explorer itself. Finally clearing out the download folder without having to manually take care of it each week or month is facilitation. In addition, this can be done by scheduling this batch file to delete folder on the windows task scheduler.
The previously tutorials about batch files:
- Batch to delete file older than– Delete files older than 7 days using batch and script.
- Batch to delete file automatically – Delete the file using the command line.
- Script to zip file – Script to zip files using cmd command.
How to Create a Batch file to delete folder with CMD.
- Create a text file and copy the below command line:
Echo batch file delete folder @RD /S /Q "D:\testfolder"
- Save like a DeleteFolder.bat. Save anywhere except D:\testfolder.
- Run the batch with a double click and check if the folder was deleted
In this case, we will delete the specified folder. In our example, we configured the batch file to delete the “testfolder” located in the D.
Explanation of batch commands.
“D:\testfolder” The basic command locates the folder.
/s parameter will delete all files contained in the directory subfolders. However, if you do not want to delete files from subfolders, remove /s parameter.
/f parameter ignores any read-only setting.
/q “quiet mode,” meaning you won’t be prompted Yes/No
Otherwise, this batch file can be scheduled on the windows task scheduler to run automatically. For more information click on the previous post: here
Using CMD to delete folders is a fast and smarter way.