| G:\beifen>REM ---------------------------------------------------------------------------------------- |
| |
| G:\beifen>REM 演示:删除指定路径下指定天数之前(以文件夹名中包含的日期字符串为准)的文件夹。 |
| |
| G:\beifen>REM 如果演示结果无误,把rd前面的echo去掉,即可实现真正删除。 |
| |
| G:\beifen>REM 本例假设文件夹名中包含的日期字符串(比如:Archive-2009-12-25) |
| |
| G:\beifen>REM ---------------------------------------------------------------------------------------- |
| |
| G:\beifen>REM 指定待删除文件夹的存放路径 |
| |
| G:\beifen>set SrcDir=G:\beifen |
| |
| G:\beifen>REM 指定天数 |
| |
| G:\beifen>set DaysAgo=26 |
| |
| G:\beifen>echo LastDate=date()-26 1>"C:\Users\Lenovo\AppData\Local\Temp\DstDate.vbs" |
| |
| G:\beifen>echo FmtDate=right(year(LastDate),4) & right("0" & month(LastDate),2) & right("0" & day(LastDate),2) 1>>"C:\Users\Lenovo\AppData\Local\Temp\DstDate.vbs" |
| |
| G:\beifen>echo wscript.echo FmtDate 1>>"C:\Users\Lenovo\AppData\Local\Temp\DstDate.vbs" |
| |
| G:\beifen>for /F %a in ( |
| |
| G:\beifen>(set "DstDate=20221106" ) |
| |
| G:\beifen>set DstDate=2022-11-06 |
| |
| G:\beifen>setlocal enabledelayedexpansion |
| |
| G:\beifen>for / %a in ("G:\beifen\*.*") do (if "%~ta" LEQ "2022-11-06" ( |
| set "FolderDate=%~na" |
| set "FolderDate=!FolderDate:~0,10!" |
| if "!FolderDate!" LEQ "2022-11-06" (if exist "%a\" (echo rd /s /q "%a" ) ) |
| ) ) |
| |
| G:\beifen>(if "2022-12-02 09:31" LEQ "2022-11-06" ( |
| set "FolderDate=2022-10-31" |
| set "FolderDate=!FolderDate:~0,10!" |
| if "!FolderDate!" LEQ "2022-11-06" (if exist "G:\beifen\2022-10-31\" (echo rd /s /q "G:\beifen\2022-10-31" ) ) |
| ) ) |
| |
| G:\beifen>(if "2022-12-02 09:31" LEQ "2022-11-06" ( |
| set "FolderDate=2022-11-01" |
| set "FolderDate=!FolderDate:~0,10!" |
| if "!FolderDate!" LEQ "2022-11-06" (if exist "G:\beifen\2022-11-01\" (echo rd /s /q "G:\beifen\2022-11-01" ) ) |
| ) ) |
| |
| G:\beifen>(if "2022-12-02 09:31" LEQ "2022-11-06" ( |
| set "FolderDate=2022-11-02" |
| set "FolderDate=!FolderDate:~0,10!" |
| if "!FolderDate!" LEQ "2022-11-06" (if exist "G:\beifen\2022-11-02\" (echo rd /s /q "G:\beifen\2022-11-02" ) ) |
| ) ) |
| |
| G:\beifen>(if "2022-12-02 09:31" LEQ "2022-11-06" ( |
| set "FolderDate=2022-11-03" |
| set "FolderDate=!FolderDate:~0,10!" |
| if "!FolderDate!" LEQ "2022-11-06" (if exist "G:\beifen\2022-11-03\" (echo rd /s /q "G:\beifen\2022-11-03" ) ) |
| ) ) |
| |
| G:\beifen>(if "2022-12-02 09:31" LEQ "2022-11-06" ( |
| set "FolderDate=2022-11-04" |
| set "FolderDate=!FolderDate:~0,10!" |
| if "!FolderDate!" LEQ "2022-11-06" (if exist "G:\beifen\2022-11-04\" (echo rd /s /q "G:\beifen\2022-11-04" ) ) |
| ) ) |
| |
| G:\beifen>(if "2022-12-02 09:31" LEQ "2022-11-06" ( |
| set "FolderDate=2022-11-07" |
| set "FolderDate=!FolderDate:~0,10!" |
| if "!FolderDate!" LEQ "2022-11-06" (if exist "G:\beifen\2022-11-07\" (echo rd /s /q "G:\beifen\2022-11-07" ) ) |
| ) ) |
| |
| G:\beifen>(if "2022-12-02 09:31" LEQ "2022-11-06" ( |
| set "FolderDate=2022-11-08" |
| set "FolderDate=!FolderDate:~0,10!" |
| if "!FolderDate!" LEQ "2022-11-06" (if exist "G:\beifen\2022-11-08\" (echo rd /s /q "G:\beifen\2022-11-08" ) ) |
| ) ) |
| |
| G:\beifen>(if "2022-12-02 09:02" LEQ "2022-11-06" ( |
| set "FolderDate=2022-11-09" |
| set "FolderDate=!FolderDate:~0,10!" |
| if "!FolderDate!" LEQ "2022-11-06" (if exist "G:\beifen\2022-11-09\" (echo rd /s /q "G:\beifen\2022-11-09" ) ) |
| ) ) |
| |
| G:\beifen>(if "2022-12-02 09:02" LEQ "2022-11-06" ( |
| set "FolderDate=2022-11-10" |
| set "FolderDate=!FolderDate:~0,10!" |
| if "!FolderDate!" LEQ "2022-11-06" (if exist "G:\beifen\2022-11-10\" (echo rd /s /q "G:\beifen\2022-11-10" ) ) |
| ) ) |
| |
| G:\beifen>(if "2022-12-02 09:02" LEQ "2022-11-06" ( |
| set "FolderDate=2022-11-11" |
| set "FolderDate=!FolderDate:~0,10!" |
| if "!FolderDate!" LEQ "2022-11-06" (if exist "G:\beifen\2022-11-11\" (echo rd /s /q "G:\beifen\2022-11-11" ) ) |
| ) ) |
| |
| G:\beifen>(if "2022-12-02 09:02" LEQ "2022-11-06" ( |
| set "FolderDate=2022-11-14" |
| set "FolderDate=!FolderDate:~0,10!" |
| if "!FolderDate!" LEQ "2022-11-06" (if exist "G:\beifen\2022-11-14\" (echo rd /s /q "G:\beifen\2022-11-14" ) ) |
| ) ) |
| |
| G:\beifen>(if "2022-12-02 09:02" LEQ "2022-11-06" ( |
| set "FolderDate=2022-11-15" |
| set "FolderDate=!FolderDate:~0,10!" |
| if "!FolderDate!" LEQ "2022-11-06" (if exist "G:\beifen\2022-11-15\" (echo rd /s /q "G:\beifen\2022-11-15" ) ) |
| ) ) |
| |
| G:\beifen>(if "2022-12-02 09:02" LEQ "2022-11-06" ( |
| set "FolderDate=2022-11-16" |
| set "FolderDate=!FolderDate:~0,10!" |
| if "!FolderDate!" LEQ "2022-11-06" (if exist "G:\beifen\2022-11-16\" (echo rd /s /q "G:\beifen\2022-11-16" ) ) |
| ) ) |
| |
| G:\beifen>(if "2022-12-02 09:02" LEQ "2022-11-06" ( |
| set "FolderDate=2022-11-17" |
| set "FolderDate=!FolderDate:~0,10!" |
| if "!FolderDate!" LEQ "2022-11-06" (if exist "G:\beifen\2022-11-17\" (echo rd /s /q "G:\beifen\2022-11-17" ) ) |
| ) ) |
| |
| G:\beifen>(if "2022-12-02 09:02" LEQ "2022-11-06" ( |
| set "FolderDate=2022-11-18" |
| set "FolderDate=!FolderDate:~0,10!" |
| if "!FolderDate!" LEQ "2022-11-06" (if exist "G:\beifen\2022-11-18\" (echo rd /s /q "G:\beifen\2022-11-18" ) ) |
| ) ) |
| |
| G:\beifen>(if "2022-12-02 09:02" LEQ "2022-11-06" ( |
| set "FolderDate=2022-11-21" |
| set "FolderDate=!FolderDate:~0,10!" |
| if "!FolderDate!" LEQ "2022-11-06" (if exist "G:\beifen\2022-11-21\" (echo rd /s /q "G:\beifen\2022-11-21" ) ) |
| ) ) |
| |
| G:\beifen>(if "2022-12-02 09:02" LEQ "2022-11-06" ( |
| set "FolderDate=2022-11-22" |
| set "FolderDate=!FolderDate:~0,10!" |
| if "!FolderDate!" LEQ "2022-11-06" (if exist "G:\beifen\2022-11-22\" (echo rd /s /q "G:\beifen\2022-11-22" ) ) |
| ) ) |
| |
| G:\beifen>(if "2022-12-02 09:02" LEQ "2022-11-06" ( |
| set "FolderDate=2022-11-23" |
| set "FolderDate=!FolderDate:~0,10!" |
| if "!FolderDate!" LEQ "2022-11-06" (if exist "G:\beifen\2022-11-23\" (echo rd /s /q "G:\beifen\2022-11-23" ) ) |
| ) ) |
| |
| G:\beifen>(if "2022-12-02 09:02" LEQ "2022-11-06" ( |
| set "FolderDate=2022-11-24" |
| set "FolderDate=!FolderDate:~0,10!" |
| if "!FolderDate!" LEQ "2022-11-06" (if exist "G:\beifen\2022-11-24\" (echo rd /s /q "G:\beifen\2022-11-24" ) ) |
| ) ) |
| |
| G:\beifen>(if "2022-12-02 09:02" LEQ "2022-11-06" ( |
| set "FolderDate=2022-11-25" |
| set "FolderDate=!FolderDate:~0,10!" |
| if "!FolderDate!" LEQ "2022-11-06" (if exist "G:\beifen\2022-11-25\" (echo rd /s /q "G:\beifen\2022-11-25" ) ) |
| ) ) |
| |
| G:\beifen>(if "2022-12-02 09:02" LEQ "2022-11-06" ( |
| set "FolderDate=2022-11-28" |
| set "FolderDate=!FolderDate:~0,10!" |
| if "!FolderDate!" LEQ "2022-11-06" (if exist "G:\beifen\2022-11-28\" (echo rd /s /q "G:\beifen\2022-11-28" ) ) |
| ) ) |
| |
| G:\beifen>(if "2022-12-02 09:02" LEQ "2022-11-06" ( |
| set "FolderDate=2022-11-29" |
| set "FolderDate=!FolderDate:~0,10!" |
| if "!FolderDate!" LEQ "2022-11-06" (if exist "G:\beifen\2022-11-29\" (echo rd /s /q "G:\beifen\2022-11-29" ) ) |
| ) ) |
| |
| G:\beifen>(if "2022-12-02 09:02" LEQ "2022-11-06" ( |
| set "FolderDate=2022-11-30" |
| set "FolderDate=!FolderDate:~0,10!" |
| if "!FolderDate!" LEQ "2022-11-06" (if exist "G:\beifen\2022-11-30\" (echo rd /s /q "G:\beifen\2022-11-30" ) ) |
| ) ) |
| |
| G:\beifen>(if "2022-12-02 09:02" LEQ "2022-11-06" ( |
| set "FolderDate=2022-12-01" |
| set "FolderDate=!FolderDate:~0,10!" |
| if "!FolderDate!" LEQ "2022-11-06" (if exist "G:\beifen\2022-12-01\" (echo rd /s /q "G:\beifen\2022-12-01" ) ) |
| ) ) |
| |
| G:\beifen>(if "2022-12-02 09:46" LEQ "2022-11-06" ( |
| set "FolderDate=2022-12-02" |
| set "FolderDate=!FolderDate:~0,10!" |
| if "!FolderDate!" LEQ "2022-11-06" (if exist "G:\beifen\2022-12-02\" (echo rd /s /q "G:\beifen\2022-12-02" ) ) |
| ) ) |
| |
| G:\beifen>endlocal |
| |
| G:\beifen>pause |
| 请按任意键继续. . . COPY |