In this tutorial we will explain how to create batch file to delete folder automatically using command line. We will continue with the series of tutorials regarding the usage of batch file. The command will erase all files and subfolder in specified folder.
This batch file can be very useful if needed to delete large folders. Using 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 a facilitation. In addition this can be done by scheduling this batch file to delete folder on 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 command line.
- Script to zip file – Script to zip files using cmd command.
Batch file to delete folder automatically.
Prepare batch file.
In this case we will delete specified folder. For example, we will configure the batch file to delete test folder folder located in the D.
Next create a text file and copy the below command line:
Echo batch file to 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 batch file to delete 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 scheduled on windows task scheduler to run automatically. For more information click on previously post: here