close

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

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 DanBrother 的頭像
    DanBrother

    DanBrother的部落格

    DanBrother 發表在 痞客邦 留言(0) 人氣()