Execute a command on a file or set of files

Computer screen showing scripts and terminal output

forfiles – a resource kit tool that iterates files in a folder, can do it on date, and let you then run a command

You can get it here: ftp://ftp.microsoft.com/ResKit/y2kfix/x86/

http://technet.microsoft.com/en-us/library/cc753551%28WS.10%29.aspx

This command should (I haven’t tested it myself) delete all files older than 30 days, under c:\temp and recurse into subdirectories.

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

Practical IT tips, straight to your inbox

Microsoft 365 updates, security alerts and plain-English tech advice for small businesses, emailed when we publish a new article.

We don’t spam! Read our privacy policy for more info.