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 file using the command line.
- Script to zip file – Script to zip files using cmd command.
Batch file to delete folder with CMD.
Prepare a batch file.
In this case, we will delete the specified folder. For example, we will configure the batch file to delete test folder located in the D.
Next 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.
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
Execute the batch file to remove folder.
Note! Remember to change the directory to match your folder.
Finally, Run as Administrator, and all files with defined extension will be deleted.
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 the fasts and smarter way.