derekmurawsky
2/25/2014 - 2:43 PM

A simple way to delete files older than X days in windows. This command is native and works as far back as server 2003.

A simple way to delete files older than X days in windows. This command is native and works as far back as server 2003.

REM Deletes files in specified path older than X days. 
forfiles -p "C:\path\to\files" -s -m *.* -d -360 -c "cmd /c del @path"

REM Alternate way to do it. Deletes all files in current directory older than X days. 
forfiles -s -m *.* -d -360 -c "cmd /c del @path"