FORFILES command to remove older files or folders (Windows Server 2008):
Delete *.log files which are older than 10 days in the c:\temp directory:
forfiles /P "c:\temp" /D -10 /M *.log /C "cmd /c del @file & echo @file was deleted!"
Delete sub-directories which are older than 10 days in the c:\temp directory:
forfiles /P "c:\temp" /D -10 /C "cmd /c if @isdir==TRUE rmdir @file /S /Q & echo @file was deleted!"
ps. TRUE must be capital
參數說明:
/P : pathname
/D : date
/M : searchmask (default '*')
/C : command
@file - return filename
@fname - return filename without extension
@path - return full path
@relpath - return relative path
@isdir - return "TRUE" if file type is a directory
return "FALSE" if file type is a file
@fsize - return file size (in bytes)
@fdate - return last modified date of the file
@ftime - return last modified time of the file
& : to seperate different commands