@echo off 
rem ****************************** 
rem * ʱɾļĿ¼ * 
rem ****************************** 
rem ʱĿ¼· 
set tempDir=%tmp%\remove_%date:~0,10% 
if not exist %tempDir% md %tempDir% 
rem ôڵĽűļ· 
set scriptFile=%tempDir%\get_date.vbs 
rem Ҫ 
set days=%~1 
if "%days%" == "" goto printUsage 
rem ĿĿ¼· 
set dirPath=%~2 
if "%dirPath%" == "" set dirPath=. 
rem Ҫļʽ 
set fileSpec=%~3 
if "%fileSpec%" == "" set fileSpec=*.* 
rem ɼڵĽűļɾĽֹ 
echo d=date()-%1 > %scriptFile% 
echo s=right("0000" ^& year(d),4) ^& "-" ^& right("00" ^& month(d),2) ^& "-" ^& right("00" ^& day(d),2) >> %scriptFile% 
echo wscript.echo s >> %scriptFile% 
for /f %%i in ('cscript /nologo %scriptFile%') do set lastDate=%%i 
rem ĿĿ¼ÿ 
for /f "tokens=1,2,3* delims=<> " %%i in ('dir "%dirPath%\%fileSpec%" /a /-c /tc') do call :proc "%%i" "%%j" "%%k" "%%l" 
goto :done 
rem ĿĿ¼Ĺ 
:proc 
rem öĴڲжǷΪЧʽ 
set fileDate=%~1 
echo %fileDate% | findstr "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]" > nul 
if errorlevel 1 goto end 
rem ö 
set fileType=%~3 
if "%fileType%" == "" goto end 
rem ö 
set fileName=%~4 
if "%fileName%" == "" goto end 
if "%fileName%" == "." goto end 
if "%fileName%" == ".." goto end 
if "%fileName%" == "ֽ" goto end 
if "%fileName%" == "ֽ" goto end 
rem ж϶ǷСڻɾĽֹ 
if "%fileDate:~0,10%" leq "%lastDate%" ( 
echo deleting "%fileName%" ... 
if "%fileType%" == "DIR" ( rd /s /q "%dirPath%\%fileName%" ) else ( del /q /f "%dirPath%\%fileName%" ) 
) 
goto end 
:error 
echo An error occurred during backuping. 
:done 
rd /s /q %tempDir% 
goto end 
:printUsage 
echo Usage: %0 ^<Days^> [Work directory] [Target file specification (can include wildcards)] 
goto end 
:end 
