- @echo off
- setlocal enabledelayedexpansion
- REM 循环所有pdf文件
- for /f "delims=" %%i in ('dir /b *.pdf ^| sort') do (
- for /f "tokens=1,2 delims=#." %%a in ("%%i") do (
- set "curFileName=%%a"
- set "curVer=%%b"
- if "!curVer!"=="pdf" set "curVer=0"
- )
- if "!lastFileName!"=="" set "lastFile=%%i"&set "lastFileName=!curFileName!"&set "lastVer=!curVer!"
- if "!curFileName!"=="!lastFileName!" (
- REM 删掉ECHO
- if !curVer! lss !lastVer! ECHO del "%%i"&set "curVer=!lastVer!"
- REM 删掉ECHO
- if !curVer! gtr !lastVer! ECHO del "!lastFile!"&set "lastFile=%%i"
- set "lastFileName=!curFileName!"&set "lastVer=!curVer!"
- ) else (
- echo ---^> !lastFileName!最新版本:!lastVer!
- REM 删掉ECHO
- ECHO rename "!lastFileName!#!lastVer!.pdf" "!lastFileName!.pdf"
- set "lastFile=%%i"&set "lastFileName=!curFileName!"&set "lastVer=!curVer!"
- echo --------------------------------------------------
- )
- )
- echo ---^> !lastFileName!最新版本:!lastVer!
- REM 删掉ECHO
- ECHO rename "!lastFileName!#!lastVer!.pdf" "!lastFileName!.pdf"
- echo --------------------------------------------------
- pause
复制代码 确认无误删掉大写的ECHO |