バッチ、ファイルbatの削除

1144 ワード

@echo off
::  :             (               )   。
::        , del   echo  ,        。
::                (  :bak-2009-12-25.log)
rem             
set SrcDir=C:/Test/BatHome
rem     
set DaysAgo=1
>"%temp%/DstDate.vbs" echo LastDate=date()-%DaysAgo%
>>"%temp%/DstDate.vbs" echo FmtDate=right(year(LastDate),4) ^& right("0" ^& month(LastDate),2) ^& right("0" ^& day(LastDate),2)
>>"%temp%/DstDate.vbs" echo wscript.echo FmtDate
for /f %%a in ('cscript /nologo "%temp%/DstDate.vbs"') do (
  set "DstDate=%%a"
)
set DstDate=%DstDate:~0,4%-%DstDate:~4,2%-%DstDate:~6,2%
setlocal enabledelayedexpansion
for /r "%SrcDir%" %%a in (*.*) do (
    set "FileDate=%%~na"
    set "FileDate=!FileDate:~4,10!"
    if "!FileDate!" leq "%DstDate%" (
        if exist "%%a" (
            echo del /f /q "%%a"
        )
    )
)
endlocal
pause