@echo off set logFile=DELETE_DOS.log set weekName=WEEK set dayName=DAY echo --------- Delete Expired Files ------------ >> %logFile% echo Start (%date% %time%) >> %logFile% echo 删除文件夹 %weekName% 下过期 (30days) 的文件, Please wait... >> %logFile% forfiles /p "%weekName%" /m *.* /d -30 >> %logFile% forfiles /p "%weekName%" /m *.* /d -30 /c "cmd /c del @path" >> %logFile% echo 删除文件夹 %dayName% 下过期(7days)的文件, Please wait... >> %logFile% forfiles /p "%dayName%" /m *.* /d -7 >> %logFile% forfiles /p "%dayName%" /m *.* /d -7 /c "cmd /c del @path" >> %logFile% echo End (%date% %time%) >> %logFile% exit
此DOS命令将删除WEEK(超过30天)和DAY(超过7天)文件夹下过期的文件,并将删除日志写入 DELETE_DOS.log
另外,有关DOS中ECHO命令的用法,稍作整理:
@ 关闭单行回显
echo off 从下一行开始关闭回显
@echo off 从本行开始关闭回显
echo on 从下一行开始打开回显
echo 显示当前是echo off/on状态
echo. 输入回车换行,空白行,同(echo, echo; echo+ echo[ echo] echo/)