Batch Script to Delete Old Files

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.
Published by aakai1056. Latest update on June 20, 2016 at 12:19 AM by owilson.
This document, titled "Batch Script to Delete Old Files," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (
Dos arithmetic
remotely access another computer using C#