试试这个,看看输出并删除echo
,如果它看起来不错:
@ECHO OFF &SETLOCAL ENABLEDELAYEDEXPANSION
SET /a XDay=7
CALL :DateToJDN "%DATE%" JDNToday
FOR /r "D:\Configs_Backup" %%a IN (*.config) DO (
FOR /f "tokens=1,4*" %%b IN ('dir /tc "%%~a"^|findstr "^[0-9]"') DO (
CALL :DateToJDN "%%b" filedate
SET /a diffdays=JDNToday-filedate
IF !diffdays! gtr %XDay% ECHO DEL /F /Q "%%~a"
)
)
GOTO :eof
:DateToJDN "DD mm/dd/yyyy" jdn=
setlocal
set date=%~1
set /A yy=%date:~-4%, mm=1%date:~-10,2% %% 100, dd=1%date:~-7,2% %% 100
set /A a=mm-14, jdn=(1461*(yy+4800+a/12))/4+(367*(mm-2-12*(a/12)))/12-(3*((yy+4900+a/12)/100))/4+dd-32075
endlocal & set %2=%jdn%
exit /B
注意:这仅适用于AM/PM
时间格式。