I recently covered how to copy and compress (ZIP) multiple files and folders and add a timestamp to the ZIP filename. All this was done using a batch file in Microsoft Windows8 (however the instructions should work fine for older versions of Windows). Using BAT (batch) files are awesome as the files can easily be scheduled to run.
Backing up vast amounts of data on a schedule is all well and good but eventually the files will start to use up too much space on your hard drive. We therefore ideally should add a means to delete the oldest backup ZIP files. Fortunately, this is very easy with a line in your BAT file (or as a separate BAT file).
Instructions to create a BAT file to delete old Files
The instructions below show how to create a BAT file to delete all files in a specific folder/directory that are older than a set amount of days.
Here is a use case:
I’ve scheduled my Google Drive files and folders to be backed up once a week. The resulting ZIP file (i.e. the backup) is 70GB. I have 500GB hard disk space available so need to delete old backup files regularly so that I have enough disk space to store new backups.
- In a notepad editor create a new file and save it as Delete Old Backups.bat
- Into the file add the following
REM Remove files backup older than 40 days forfiles /p "C:backupfolder" /s /m *.* /c "cmd /c Del @path" /d -40
- Change “C:backupfolder” to the directory to which you are saving the files you want to delete on a schedule. Note that the -40 refers to the day after which all files should be deleted so change the -40 if required.
- Save the file and double click it to test.
- Add to a scheduled task if required.
Get solutions from others. Click Notify me of follow-up comments via e-mail when you leave a comment below.