Does anyone know of a good way to delete files based on their age and have it done periodically, say using a batch file and windows scheduler? (Or any other decent software that would do this as well)
Does anyone know of a good way to delete files based on their age and have it done periodically, say using a batch file and windows scheduler? (Or any other decent software that would do this as well)
+1 for 'forfiles"
here's what I use in a batch file that runs nightly:
forfiles -pE:\myfolder\mysubfolder -m*.* -d-5 -c"cmd /C del /q @FILE"
You can use the forfiles commnad. Just use the windows scheduler to schedule it directly.
Some more examples.
Yes, I've got one we use. Found it online and made some modifications to it.
This would be run as
and would delete all the log files in C:\Temp and its subdirectories more than 5 days old
Ah, found the original post
Here's a Powershell script you can use in a scheduled task. (Also used this in this answer for purging IIS log files).
Change the folder path to your target, tweak AddDays as appropriate. -30 removes things older than 30 days.