Delete Files older than X days

Example Delete all files with starting with blah in Folder “FolderName” older than 30 days.

forfiles -p C:\FolderName -m blah*.* /d -30 -c "cmd /c del @path"

Newer Windows use slightly different parameters - e.g. Windows 2012

forfiles /P "C:\Users\remoteeir\Desktop\PingTest" /M PingTestResults_*.* /D -3 /C "cmd /c del @path"
  • tech-notes/scripts/delete-files-older-than.txt
  • Last modified: 2019/06/12 10:16
  • by gerardorourke