求一批处理文件,能够删除指定目录下(D:\testfile)的今天(也就是执行批处理时当天)前创建的所有文件。小弟从没写过bat文件,请高手帮忙写一个,谢了
------解决方案--------------------------------------------------------
- BatchFile code
@echo offecho 今天是:%date%echo.set /a "today=%date:~0,4%*365+%date:~5,2%*30+%date:~8,2%"setlocal enabledelayedexpansionfor /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 OKpause>nul
------解决方案--------------------------------------------------------
test.bat
- BatchFile code
@echo offrem 指定待删除文件的存放路径set "SrcDir=D:\Test\"rem 假设系统日期格式是yyyy-mm-ddset "DstDate=%date:~0,10%"for /f "delims=/" %%a in ('dir /s /b /a-d "%SrcDir%"') do ( call :CompareTime "%%a")goto :eof:CompareTimefor /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)