Metro Vancouver: 1.604.601.2118 | Toll-free: 1.855.PLACE.ONE (752.2366) [email protected]

Deleting Files Older Than X Number of Days

Do you need to delete a lot of files older than a certain number of days? Instead of using robocopy trickery, here's a quicker way to do just that from the command-line on Windows.

Example 1:

forfiles /d -120 /m *.log /c "cmd  /c del @path"

This example deletes all .log files in the current directory that were last modified on or more than 120 days ago.

Example 2:

forfiles /d -10/25/2014 /m *.log /c "cmd  /c del @path"

This example deletes all .log files in the current directory that were last modified on or before October 25, 2014.

Example 3:

forfiles /d -10/25/2014 /m *.log /p "D:\somefolder" /c "cmd  /c del @path"

This example deletes all .log files in D:\somefolder that were last modified on or before October 25, 2014.

Notes: