Thursday, 24 April 2014

Batch file - removing files older than x

I needed to remove IIS logs older than a number of days due to the C drive filling up - I found some information on the net with regards forfiles (instead of using Powershell which was my first port of call but due to the server running Windows 2003).

The script removes files older than 3 days and outputs the errors to a log file (or should - nothing in my log file at present but I've had no errors to date!).

forfiles /p C:\WINDOWS\system32\LogFiles\W3SVC100\ /s /m *.* /d -3 /c "cmd /c del @path" >> C:\Temp\remove_file_log.txt

No comments:

Post a Comment