Forfiles, rotate files

If you are like us we have been searching for an easy way to delete files from a folder that are X days old there are lots of programs out there to install that will do this but a hidden little gem in windows server 2003 call forfiles can do this easy.  Example below deletes all files older than 10 days in the folder d:\sql-backup it also looks in any subfolders below the main folders and does the same.  Great little tool

Forfiles /p d:\sql-backup /s /m *.* /d -10 /C “cmd /c del /q @path”

Another great thing to use forfiles for is if you want to setup log rotation on a windows iis server for example:

C:\WINDOWS\system32\forfiles.exe /p E:\IISLogfiles /s /m *.log /d -60 /C “cmd /c del /q @file”

 

Be the first to comment

Leave a Reply