29 May 2012

How to delete files older than X days from command line

You might need to use forfiles command for that. Following example removes all files older than 50 days from current directory :

forfiles /d -50 /c "cmd /c del @path"

For detailed instructions on forfiles switches see:

forfiles /?

Plain forfiles lists all files in current directory. Option /D -50 filters out files older than 50 days. And /c "cmd /c del @path" executes the command prompt with del command and exit’s from that command prompt.

1 comment:

  1. For scheduling this command read this article http://raunomagi.blogspot.com/2013/01/easily-schedule-deletion-of-older-files.html

    ReplyDelete