批处理删除指定日期之外的数据文件


cls
Title [删除20天以前的备份文件]


@echo off
SET TT=20 
set p1=%date:~0,4%
set p2=%date:~5,2%
set p3=%date:~8,2%
set files=f:\wan\test\test3
setlocal enabledelayedexpansion
for /l %%a in (1,1,3) do (
for /f "delims=0 tokens=*" %%i in ("!p%%a!") do set p%%a=%%i
)
if %p3% gtr %TT%  goto ppp
:nxt
set/a p2-=1
if %p2% equ 0 set/a p1-=1&&set p2=12
SET/a PN1=%p1%%%4
set PN2=28
if %PN1% EQU 0 set pN2=29
for /f "tokens=%p2%" %%i in ("31 %pN2% 31 30 31 30 31 31 30 31 30 31") do set/a p3=%p3%+%%i
if %p3% leq %tt% goto nxt
:ppp
set/a p3=%p3%-%tt%
set p2=0%p2%
set p2=%p2:~-2,2%
set p3=0%p3%
set p3=%p3:~-2,2%
for /r "%files%" %%i in (*.*) do set t=%%~ti &&call :loop "%%~fi"

goto :eof
:loop
if not "%~1" == "%~f0" (
IF %p1%%p2%%p3% gtr %t:~0,4%%t:~5,2%%t:~8,2% del %1
)
 

你可能感兴趣的:(职场,休闲,批处理删除)