Batch Script to Delete Old Files

December 2016

Batch files can be created for customized tasks such as cleaning up older systems or copying files from one folder to another as a backup.

Batch Script Command to Delete Files

If you would like to create a batch script that can be used to copy files older than 30 days from one folder to another while simultaneously deleting the old files from the source folder, here's a sample batch script that can automate the task:
forfiles /p "PATH" /s /d -30 /c "cmd /c del @file : date >= 30 days >NUL"

Note that the PATH in the given code should be substituted by the path where you would like your files to be deleted. If there are no spaces in the path, the - symbol is not needed.

This command can be saved in a .bat file and may be scheduled with other automated tasks.

N.B. More than one directory may be included in this command.

Related :

This document entitled « Batch Script to Delete Old Files » from CCM ( is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.