日期:2014-05-17 浏览次数:21011 次
@echo off
echo 今天是:%date%
echo.
set /a "today=%date:~0,4%*365+%date:~5,2%*30+%date:~8,2%"
setlocal enabledelayedexpansion
for /f "delims=" %%i in ('dir c:\test\*.* /s /b /a-d') do (
set tt=%%~ti
set /a "dd=!tt:~0,4!*365+!tt:~5,2!*30+!tt:~8,2!"
if !dd! lss %today% (echo 删除当前文件:%%i !tt!)&&(del "%%i" /f /a /q)
)
echo.
echo OK
pause>nul
------解决方案--------------------
test.bat
@echo off
rem 指定待删除文件的存放路径
set "SrcDir=D:\Test\"
rem 假设系统日期格式是yyyy-mm-dd
set "DstDate=%date:~0,10%"
for /f "delims=/" %%a in ('dir /s /b /a-d "%SrcDir%"') do (
call :CompareTime "%%a"
)
goto :eof
:CompareTime
for /f "skip=5 tokens=1-2 delims= " %%h in ('dir /a-d /tc %1') do (
if "%%h" neq "%DstDate%" (
if exist %1 (
del /a /f /q %1
)
)
goto :eof
)