- @echo off & setlocal enabledelayedexpansion
- pushd "C:\backup"
- call :Date2Day %date:~0,-3% 10 Day
- for /r %%i in (*.bak) do (
- for /f "tokens=1 delims= " %%j in ("%%~ti") do set "filedate=%%j" & set "filedate=!filedate:-=/!"
- if !filedate! LEQ %day% (
- set /p=Del-%%i<nul
- del "%%~i">nul 2>nul && echo ...OK! || echo ...Fail!
- )
- )
- pause
- exit
-
- :Date2Day //from http://www.cnblogs.com/mac_arthur/archive/2011/12/12/2285013.html
- setlocal
- for /f "tokens=1-3 delims=/-:\, " %%a in ('echo/%~1') do (
- set /a yy=%%a,mm=100%%b%%100,dd=100%%c%%100)
- set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,j=153*m+2
- set /a j=j/5+dd+y*365+y/4-y/100+y/400-2472633
- set /a i=j-%~2,a=i+2472632,b=4*a+3,b/=146097,c=-b*146097,c/=4,c+=a
- set /a d=4*c+3,d/=1461,e=-1461*d,e/=4,e+=c,m=5*e+2,m/=153,dd=153*m+2,dd/=5
- set /a dd=-dd+e+1,mm=-m/10,mm*=12,mm+=m+3,yy=b*100+d-4800+m/10
- (if %mm% LSS 10 set mm=0%mm%)&(if %dd% LSS 10 set dd=0%dd%)
- endlocal&set %~3=%yy%%f%/%mm%%f%/%dd%&goto :EOF
复制代码 在网上百度了下日期计算代码,懒得写了.. |