N 일 전이 나 지 정 된 날짜 시간(앞 뒤)에 생 성(또는 수정)된 파일 을 일괄 처리 합 니 다.

핵심 코드:

@echo off
:: by oicu#lsxk.org
:: 15:17 2011-1-13

::            N       , forfiles  
FORFILES /P "C:\    " /S /M *.log /D -3 /C "cmd /c if @isdir==FALSE echo del @file"
::     (  )      :/D -yyyy/mm/dd

::       
::     :              (  )
::   dir /tc           ,  dir  dir /tw
::         ,     for+find,    。

cd /d     
::         , for /r . %%a in (*)

::         
for %%a in (*) do echo "%%~ta"
::         
for %%a in (*) do for /f "tokens=1,2* delims= " %%b in (
'dir /tw "%%a" ^| find /i "%%~nxa"'
) do echo "%%b %%c"

::              (    )
for %%a in (*) do if "%%~ta" gtr "2008-04-01" echo del "%%a"

::             
for %%a in (*) do for /f "tokens=1,2* delims= " %%b in (
'dir /tc "%%a" ^| find /i "%%~nxa"'
) do echo "%%b %%c"

::              ,              ,   
::  gtr lss。     ,      ,    else 。
for %%a in (*) do for /f "tokens=1,2* delims= " %%b in (
'dir /tc "%%a" ^| find /i "%%~nxa"') do (
  if "%%b" gtr "2010-12-15" (
    echo del "%%a"
  ) else (
    if "%%b" equ "2010-12-15" if "%%c" gtr "14:50" echo del "%%a"
  )
)

::                    ,    set       ,
::              ,    vbs      ,      
::   vbs    。

::  10      ,      OldDate
echo wscript.echo dateadd("d",-10,date)>GetOldDate.vbs
for /f %%a in ('cscript /nologo GetOldDate.vbs') do set OldDate=%%a
echo %OldDate%
del GetOldDate.vbs

:: VBScript   Format  ,Year、Month、Day            
::  10   ,              
echo wscript.echo dateadd("d",-10,date)>GetOldDate.vbs
for /f "tokens=1,2,3* delims=-/. " %%i in ('cscript /nologo GetOldDate.vbs') do (
  set y=%%i
  set m=%%j
  set d=%%k
)
if %m% LSS 10 set m=0%m%
if %d% LSS 10 set d=0%d%
set OldDate=%y%-%m%-%d%
echo %OldDate%
del GetOldDate.vbs


::     ,           
::   10        (     )
echo wscript.echo dateadd("d",-10,date)>GetOldDate.vbs
for /f "tokens=1,2,3* delims=-/. " %%i in ('cscript /nologo GetOldDate.vbs') do (
  set y=%%i
  set m=%%j
  set d=%%k
)
if %m% LSS 10 set m=0%m%
if %d% LSS 10 set d=0%d%
set OldDate=%y%-%m%-%d%
del GetOldDate.vbs
for %%a in (*) do for /f "tokens=1,2* delims= " %%b in (
'dir /tc "%%a" ^| find /i "%%~nxa"') do (
  if "%%b" lss "%OldDate%" echo del "%%a"
)

::   10        (     )
echo wscript.echo dateadd("d",-10,date)>GetOldDate.vbs
for /f "tokens=1,2,3* delims=-/. " %%i in ('cscript /nologo GetOldDate.vbs') do (
  set y=%%i
  set m=%%j
  set d=%%k
)
if %m% LSS 10 set m=0%m%
if %d% LSS 10 set d=0%d%
set OldDate=%y%-%m%-%d%
del GetOldDate.vbs
for %%a in (*) do if "%%~ta" lss "%OldDate%" echo del "%%a"


::      echo del  del,          ,      。

pause
goto :eof

좋은 웹페이지 즐겨찾기