这里有一种方法可以做到这一点在Windows批处理:
@echo off
setlocal EnableDelayedExpansion
set m=100
for %%a in (January February March April May June^
July August September October November December) do (
set /A m+=1
set month[!m:~-2!]=%%a
)
:: Do the rename. Remove echo after you verify output.
for %%a in (*.pdf) do (
set "file=%%~dpnxa" & set "file=!file:\=\\!"
echo file=!file!
Call :GetFileMonthNum "!file!" C mnum
Call set fmonth=%%month[!mnum!]%%
echo ren "%%a" "%%~na !fmonth!%%~xa"
echo ren "%%~na.xls" "%%~na !fmonth!.xls"
)
goto :eof
:GetFileMonthNum <file> <created/accessed/modified> <outVar>
setlocal
for /f "tokens=1-3" %%a in (
'wmic datafile where "name='%~1'" get creationdate^,lastaccessed^
^,lastmodified^|findstr /r "\.*-.*"'
) do (
set opts=%2
if "!opts:~0,1!" EQU "C" set "dt=%%a"
if "!opts:~0,1!" EQU "A" set "dt=%%b"
if "!opts:~0,1!" EQU "M" set "dt=%%c"
set "mm=!dt:~4,2!"
)
endlocal & set %~3=%mm%
exit /b
而且,你怎么确定本月份的名称PDF文件名的地方? –