急求各位帮忙修改下如下批处理脚本,我水平有限,改了好久都没有改好
实现:删除n天以前类似yyyymmdd这样的文件夹及其文件的功能,
我的文件夹格式类似yyyymmdd,要求以文件夹中的日期为时间进行判断,- @echo off
- rem 指定待删除文件夹的存放路径
- set SrcDir=F:\201221test\smppbillstore
- 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 /d %%a in ("%SrcDir%/*.*") do (
- if "%%~ta" leq "%DstDate%" (
- set "FolderDate=%%~na"
- set "FolderDate=!FolderDate:~8,10!"
- if "!FolderDate!" leq "%DstDate%" (
- cd %SrcDir%
- if exist "%%a/" (
- echo rd /s /q "%%a"
- )
- )
- )
- )
- endlocal
- pause
复制代码
|