Delete old files via command line

27. October 2014 0 By admin
VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)

Ever wanted to delete files of a certain type but keep files not older than 30 days? Well, here is a fast and simple way to clean up, for example old IIS log files in seconds.

Open  command line and type the following:

forfiles /P C:\inetpub\logs\LogFiles /s /m *.log /d -30 /C “C:\Windows\System32\CMD.exe /C DEL /F /Q @PATH” 

The text in italic bold are parameters you can change to your needs. Adjust the “-30” to age of log files to keep (in days) and the path to the log files, in this case “C:\inetpub\logs\LogFiles”.

This can be used to delete many file types. For this edit the “*.log” to the needed filter