@echo off&setlocal EnableDelayedExpansion
::取2天之前的日期.set _tian=13下面这句中的13代表天数.
set "_tian=1"
>tmptmp.vbs echo wscript.echo dateadd("d",%_tian%,date)
for /f "tokens=1,2,3* delims=-" %%i in ('cscript logo tmptmp.vbs') do (
set "y=%%i"&set "m=%%j"&set "d=%%k"
)
set "rq=%y%-%m%-%d%"
echo.&echo 注意:即将删除 %rq% 以前建立的文件
for /f "delims=" %%a in ('dir/b/a-d E:\test_batch\*.*') do (
echo %%a>>fyr21.txt
set "a=0"
for /f "skip=4 delims=" %%b in ('dir/tc "E:\test_batch\%%a"') do (
set /a "a+=1"
if !a! equ 1 (
set "var=%%b"
for /f "tokens=1 delims= " %%c in ("!var!") do set "str=%%c"
echo !str!>>fyr22.txt
if !str! lss !rq! del /q "E:\test_batch\%%a"
)))
del/q tmptmp.vbs
pause
E:\>(
echo F2010新帐套_2012-05-111201.dbb 1>>fyr21.txt
set "a=0"
for /F "skip=4 delims=" %b in ('dir/tc "E:\test_batch\F2010新帐套_2012-05-11120
1.dbb"') do (
set /a "a+=1"
if !a! EQU 1 (
set "var=%b"
for /F "tokens=1 delims= " %c in ("!var!") do set "str=%c"
echo !str! 1>>fyr22.txt
if !str! LSS !rq! del /q E:\test_batch\F2010新帐套_2012-05-111201.dbb
)
)
)
找不到文件
E:\>for /F "tokens=1,2,3* delims=-" %i in ('cscript /nologo tmptmp.vbs') do (set
"y=%i" & set "m=%j" & set "d=%k" )
E:\>(set "y=2012" & set "m=05" & set "d=17" )
E:\>set "rq=2012-05-17"
E:\>echo. & echo 注意:即将删除 2012-05-17 以前建立的文件
注意:即将删除 2012-05-17 以前建立的文件
E:\>for /F "delims=" %a in ('dir/b/a-d E:\test_batch\*.*') do (
echo %a 1>>fyr21.txt
set "a=0"
for /F "skip=4 delims=" %b in ('dir/tc "E:\test_batch\%a"') do (
set /a "a+=1"
if !a! EQU 1 (
set "var=%b"
for /F "tokens=1 delims= " %c in ("!var!") do set "str=%c"
echo !str! 1>>fyr22.txt
if !str! LSS !rq! del /q "E:\test_batch\%a"
)
)
)
E:\>(
echo F2010新帐套.dbb 1>>fyr21.txt
set "a=0"
for /F "skip=4 delims=" %b in ('dir/tc "E:\test_batch\F2010新帐套.dbb"') do (
set /a "a+=1"
if !a! EQU 1 (
set "var=%b"
for /F "tokens=1 delims= " %c in ("!var!") do set "str=%c"
echo !str! 1>>fyr22.txt
if !str! LSS !rq! del /q "E:\test_batch\F2010新帐套.dbb"
)
)
)
找不到文件
E:\>(
echo F查询帐套.bak 1>>fyr21.txt
set "a=0"
for /F "skip=4 delims=" %b in ('dir/tc "E:\test_batch\F查询帐套.bak"') do (
set /a "a+=1"
if !a! EQU 1 (
set "var=%b"
for /F "tokens=1 delims= " %c in ("!var!") do set "str=%c"
echo !str! 1>>fyr22.txt
if !str! LSS !rq! del /q "E:\test_batch\F查询帐套.bak"
)
)
)
找不到文件
E:\>(
echo F查询帐套.dbb 1>>fyr21.txt
set "a=0"
for /F "skip=4 delims=" %b in ('dir/tc "E:\test_batch\F查询帐套.dbb"') do (
set /a "a+=1"
if !a! EQU 1 (
set "var=%b"
for /F "tokens=1 delims= " %c in ("!var!") do set "str=%c"
echo !str! 1>>fyr22.txt
if !str! LSS !rq! del /q "E:\test_batch\F查询帐套.dbb"
)
)
)
找不到文件