删除目录
/P 表示目录
/S 表示递归向下查询子目录
/D 表示date -460 意思是460天以前 或者 -2018/11/9 表示这个日期以前的
/C 开始执行命令 内部还有一个cmd
@ISDIR==TRUE 表示判断是不是目录
RD 表示删除目录(文件夹)/s 表示可以删除非空的文件夹 /q 安静模式,不需要停下来回应是否因该删除
示例:
E:\data\bpt\log\ABC>FORFILES /P E:\data\bpt\log /S /D -460 /C “cmd /c if @ISDIR
==TRUE RD /s /q @PATH” >>E:\data\bpt\log\del.log
rem @echo off
rem logpath
set LogPath="C:\OMD_Feeder_Client\OMD_Feeder_Client_v1.9.4\log"
rem record del_log process
set DelLog="C:\OMD_Feeder_Client\OMD_Feeder_Client_v1.9.4\del_old.log"
echo ----------------------------------------------- >>%DelLog%
rem days
set DaysAgo=7
echo delete the old files start at %Date% - %time% >>%DelLog%
rem del cmd
rem FORFILES /P C:\OMD_Feeder_Client\OMD_Feeder_Client_v1.9.4 /S /D -460 /C "cmd /c if @ISDIR==TRUE echo @PATH" >>%DelLog%
FORFILES /p %LogPath% /s /m *.* /d -%DaysAgo% /C "cmd /c del @path" >>%DelLog%
echo delete the old files end of %Date% - %time% >>%DelLog%
echo ----------------------------------------------- >>%DelLog%
rem @echo off
rem logpath
set LogPath="E:\data(1)\data\bpt\log"
rem record del_log process
set DelLog="%LogPath%\del_old.log"
echo ----------------------------------------------- >>%DelLog%
rem days
set DaysAgo=30
echo delete the old files start at %Date% - %time% >>%DelLog%
rem del cmd
rem FORFILES /P E:\data\bpt\log /S /D -460 /C "cmd /c if @ISDIR==TRUE echo @PATH" >>%DelLog%
FORFILES /P %LogPath% /S /D -%DaysAgo% /C "cmd /c if @ISDIR==TRUE echo @PATH && RD /s /q @PATH" >>%DelLog%
echo delete the old files end of %Date% - %time% >>%DelLog%
echo ----------------------------------------------- >>%DelLog%
win7下创建定时任务