Just stumbled on this function and had a need to delete temp files that were 30 days old. This works great and I split it out to delete sub folders as well!
@echo off
rem ##### Script deletes files and folders older then 30 days #####
echo deleting files older then 30 days
rem ##### this checks and deletes files that are older then 30 days #####
rem ##### in server 2008 if you delete files first then the date stamp changes on directories so directory delete is done first #####
forfiles /p "c:\temp" /s /d -0 /c "cmd /C del @FILE /q"
rem ##### this checks and deletes directories and sub directories that are older then 30 days #####
ForFiles /P "c:\temp" /D -0 /C "cmd /c if @isdir==TRUE RD /Q /S @FILE "
No comments:
Post a Comment