Deleting files based on their Date

If you are perfoming regular automated backups (like you should), You’ll soon find you are running out of space and need to start deleting old backups.

Here is a really simple way to delete files that are more than x days old.

It can easily be worked into a batch file to be run at the same time as an automated backup.

Forfiles -p c:\path -s -m *.* -d -14 -c "cmd /c del /q @path"

Change the *.* to a more specific file mask (eg: backup*.zip). The 14 specifies files older than 14 days, so change this to suit your purposes.

If you want to check what files will be deleted, this will display them:

Forfiles -p c:\path -s -m *.* -d -14 -c "Cmd /C Echo 0x22@Path\@File0x22"

You May Also Like

About the Author: John

Leave a Reply

Your email address will not be published. Required fields are marked *