Furthermore, in this tutorial, we will explain the way to create a batch to delete file automatically using the command line. This is useful if you have limited space on an HDD and need to delete files on some folders that populated automatically. In my case SQL backups folder.
After the tutorial where we created batch to zip files, this is another 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 a script to delete the file automatically. All of that without installing any third-party software. In fact, this example will show steps for creating a batch file and you can use Task Scheduler to run.
Other useful batch tutorials:
- Script to zip files – Script to zip files using cmd command.
- Delete file older than. – Cmd delete file.
- Batch to delete file older than– Script to 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 an extension of the file.
- Script file to delete all files
Batch to delete file based on the extension.
In fact, Batch files are scripts that can run to perform tasks on your 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 Script 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 be deleted.
CMD delete all files in folder.
As a result, we will tell the cmd remove all files in folder that are located in the Test folder.
echo cmd delete all files in folder
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 be deleted.
Also, you can use Task Scheduler to create scheduled task.
————————————————————————————–