Create batch to delete file automatically – command
1. Create batch to delete file
automatically – Command Line
Source: http://www.get-itsolutions.com
2. Create batch to delete file automatically
In this tutorial we will explain way to create batch file 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.
3. Create batch to delete file automatically
You will need to delete those files manually every day and this
is not good practice. Instead you can create batch to delete
file automatically. All of that without installing any Third-party
software. This example will show steps for creating batch file
and you can use Task Scheduler to run.
4. Create batch to delete file automatically
Batch to delete file automatically
We will explain two methods:
• Batch file to delete file based on extension of the file.
• Batch file to delete all files
5. Batch file to delete file based on extension of the file.
Batch files are scripts that can run to perform tasks on you
system. They are the best ways to save time. In your case we
will delete files on specific folders. For the example, we will
tell the batch file to delete .txt files that are located in the Test
folder.
6. Batch file to delete file based on extension of the file.
Create a text file and copy the below command line:
echo deleting file
del "D:Test_1Test*.txt" /s /f /q
Echo Done
7. Batch file to delete file based on extension of the file.
Save like a delete.bat. Save anywhere except D:Test_1Test .
del "D:Test_1Test*.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.
8. Batch file to delete all files
We will tell the batch file to delete all files that are located in the Test folder.
echo deleting file
del "D:Test_1Test*.*" /s /f /q
Echo Done
Run as Administrator and all files located in the “Test” folder will be deleted.
9. Other useful batch tutorial:
• Script to zip files.
• Delete file older than.
• Batch file delete folder.