A relatively unknown batch file utility which ships with Windows (Vista) is forfiles:

Selects a file (or set of files) and executes a command on that file. This is helpful for batch jobs.

On all of my workstations I have a task scheduled to run nightly:

forfiles /p "%TEMP%" /m *.* /s /d -28 /c "cmd /c if @isdir==TRUE (echo rmdir @path) else (echo del /q @path)"

This deletes all files from my temp directory older than 28 days.

I used to have a Perl script that does this, and I’ve seen this done with complicated for syntax, however this doesn’t require anything to be installed, and is much simpler :)

Leave a Reply