按楼主要求写了一个。借用一下时间函数,不知合不合要求- @echo off
- set filepath=d:\
- set bakpath=d:\bak\
-
- for /f "tokens=1-3 delims=/-.: " %%a in ("%date% %time%") do (
- set "bkfn=%%a%%b%%c"&call :datetodays %%a %%b %%c days
- )
- copy /Y %filepath%1.xls %bakpath%%bkfn%.xls >nul 2>nul&&echo 备份%filepath%1.xls到%bakpath%%bkfn%.xls成功||echo %filepath%1.xls文件不存在
-
- set/a dayo=days-60
-
- for /f "tokens=1-3,6 delims=- " %%i in ('dir/OD %bakpath%*.xls ^| find "xls"') do (
-
- call :datetodays %%i %%j %%k old_d
- if %old_d% lss %dayo% del /Q %bakpath%%%l>nul&&echo 备份文件%bakpath%%%l过期,已被删除
- )
- echo 处理完毕!
-
- pause&goto :eof
-
- :datetodays
- setlocal ENABLEEXTENSIONS
- set yy=%1&set mm=%2&set dd=%3
- set /a dd=100%dd%%%100,mm=100%mm%%%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
- endlocal&set %4=%j%&goto :EOF
复制代码
|