代码如下:@echo off::演示:删除指定路径下指定天数之前(以文件名中包含的日期字符串为准)的文件。::如果演示结果无误,把del前面的echo去掉,即可实现真正删除。::本例假设文件名中包含的日期字符串(比如:bak-2009-12-25.log)rem 指定待删除文件的存放路径set SrcDir=C:/Test/BatHomerem 指定天数set DaysAgo=1>"%temp%/DstDate.vbs" echo LastDate=date()-%DaysAgo%>>"%temp%/DstDate.vbs" echo FmtDate=right(year(LastDate),4) ^& right("0" ^& month(LastDate),2) ^& right("0" ^& day(LastDate),2)>>"%temp%/DstDate.vbs" echo wscript.echo FmtDatefor /f %%a in ('cscript /nologo "%temp%/DstDate.vbs"') do ( set "DstDate=%%a")set DstDate=%DstDate:~0,4%-%DstDate:~4,2%-%DstDate:~6,2%setlocal enabledelayedexpansionfor /r "%SrcDir%" %%a in (*.*) do ( set "FileDate=%%~na" set "FileDate=!FileDate:~4,10!" if "!FileDate!" leq "%DstDate%" ( if exist "%%a" ( echo del /f /q "%%a" ) ))endlocalpause