Furthermore in this tutorial we will explain way to create batch to delete file automatically using command line. This is useful if you have limited space on a HDD and need to delete files on some folders that populated automatically. In my case SQL backups folder.
After tutorial where we created batch to zip files, this is other useful tutorial for your daily jobs.
You will need to delete those files manually every day and this is not good practice. On the other hand you can create script to delete file automatically. All of that without installing any Third-party software. In fact this example will show steps for creating batch file and you can use Task Scheduler to run.
Other useful batch tutorial:
- Script to zip files – Script to zip files using cmd command.
- Delete file older than. – Delete file using command line.
- Batch to delete file older than– Delete files older than 7 days using batch and script.
Batch to delete file automatically.
Furthermore we will explain two methods:
- Batch file to delete file based on extension of the file.
- Script file to delete all files
Batch to delete file based on extension.
In fact Batch files are scripts that can run to perform tasks on you system. They are the best ways to save time. In fact we will delete files on specific folders. For example, we will tell the batch file to delete .txt files that are located in the Test folder.
Create a text file and copy the below command line:
echo Batch to delete file del "D:\Test_1\Test\*.txt" /s /f /q echo Done!
Save like a delete.bat. Save anywhere except D:\Test_1\Test\ .
del “D:\Test_1\Test\*.txt” The basic command locates the folder.
/s parameter will delete all files contained in the directory subfolders. 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
Note! Remember to change the directory to match your computer.
Run as Administrator and all files with defined extension will deleted.
Script file to delete all files.
As a result we will tell the Script file to delete all files that are located in the Test folder.
echo deleting file del "D:\Test_1\Test\*.*" /s /f /q echo Done!
At this point run as Administrator and all files located in the “Test” folder will deleted.
Also you can use Task Scheduler to create scheduled task.