溶液中分批:
@echo off &setlocal
set "StartFolder=C:\Reports"
call:GetInternational
cd /d "%StartFolder%"
for /f "delims=" %%a in ('dir /b /ad ^| findstr "^[0-3][0-9]-[0-1][[0-9]-201[0-9]$"') do set "OldFolder=%%~a"
REM get the seconds from the folders date
call:GetSecs "%OldFolder%" "12:00:00" OldFolderSecs
REM 8 days = 691200 sec
set /a StartSecs=OldFolderSecs-691200
call:GetTMS "%StartSecs%" yyyy mm dd
set "StartTMS=%dd%-%mm%-%yyyy%"
REM 2 days = 172800 sec
set /a EndSecs=OldFolderSecs-172800
call:GetTMS "%EndSecs%" yyyy mm dd
set "EndTMS=%dd%-%mm%-%yyyy%"
for %%a in ("%OldFolder%\*.xls") do echo ren "%%~a" "%%~na %StartTMS%-%EndTMS%%%~xa"
goto:eof
:GetInternational
:: Sets a bundle of variables by reading the registry settings
for /f "tokens=1,2*" %%a in ('reg query "HKCU\Control Panel\International"') do set "%%a=%%c"
goto :eof
:GetSecs "dateIn" "timeIn" secondsOut
:: Output: Seconds elapsed since 1th Jan. 1970 00:00:00
setlocal
set "dateIn=%~1"
for /f "tokens=2" %%i in ("%dateIn%") do set "dateIn=%%i"
for /f "tokens=1-3 delims=%sDate%" %%a in ("%dateIn%") do (
if %iDate%==0 set /a mm=100%%a%%100,dd=100%%b%%100,yy=10000%%c%%10000
if %iDate%==1 set /a dd=100%%a%%100,mm=100%%b%%100,yy=10000%%c%%10000
if %iDate%==2 set /a yy=10000%%a%%10000,mm=100%%b%%100,dd=100%%c%%100
)
for /f "tokens=1-3 delims=%sTime%%sDecimal% " %%a in ("%~2") do (
set "hh=%%a"
set "nn=%%b"
set "ss=%%c"
)
if 1%hh% lss 20 set hh=0%hh%
if "%nn:~2,1%" equ "p" if "%hh%" neq "12" (set "hh=1%hh%" &set /a hh-=88)
if "%nn:~2,1%" equ "a" if "%hh%" equ "12" set "hh=00"
if "%nn:~2,1%" geq "a" set "nn=%nn:~0,2%"
set /a hh=100%hh%%%100,nn=100%nn%%%100,ss=100%ss%%%100
set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,j=153*m+2,j=j/5+dd+y*365+y/4-y/100+y/400-2472633,j=j*86400+hh*3600+nn*60+ss
endlocal &set "%~3=%j%"
goto :eof
:GetTMS
setlocal ENABLEEXTENSIONS
set /a i=%1,ss=i%%60,i/=60,nn=i%%60,i/=60,hh=i%%24,dd=i/24,i/=24
set /a a=i+2472632,b=4*a+3,b/=146097,c=-b*146097,c/=4,c+=a
set /a d=4*c+3,d/=1461,e=-1461*d,e/=4,e+=c,m=5*e+2,m/=153,dd=153*m+2,dd/=5
set /a dd=-dd+e+1,mm=-m/10,mm*=12,mm+=m+3,yy=b*100+d-4800+m/10
(if %mm% LSS 10 set mm=0%mm%)&(if %dd% LSS 10 set dd=0%dd%)
(if %hh% LSS 10 set hh=0%hh%)&(if %nn% LSS 10 set nn=0%nn%)
if %ss% LSS 10 set ss=0%ss%
endlocal&set %4=%dd%&set %3=%mm%&set %2=%yy%&goto :EOF
查看輸出和除去如果看起來不錯,可以在ren
之前使用echo
。在批量
©Dostips
日期操作是一項艱鉅的任務。我建議你[標籤:VBScript]。 –
@LS_dev我設法得到結果,請檢查一次。 – debal