- ::改扩展名.docx为.doc,重名则添加/修改数字后缀。
- @echo off
- setlocal enableDelayedExpansion
- for /f "delims=" %%i in ('dir /b/a-d/s *.docx')do (
- if exist "%%~dpni.doc" (
- call :docx2doc docName "%%i"
- ren "%%i" "!docName!"
- )else ren "%%i" "%%~ni.doc"
- )
- goto :eof
- ::====完====
-
- :docx2doc docName docxPath
- setlocal
- pushd %~dp2
- set/am=1,@2=1
- for /l %%n in (0 1 9)do set _%%n=%%n
- set "strNum=%~n2"
- :numlp ::取末尾数字
- if defined _%strNum:~-1% (
- set/aLen+=1,m*=10
- set n=%strNum:~-1%%n%
- set strNum=%strNum:~,-1%
- goto :numlp
- )
- if "%Len%"=="" set/a num1=Len=1&goto :nend
- :nnext
- set/an1=1%n%+1
- set/ah=n1/m
- set num1=!@%h%!!n1:~-%Len%!
- if "%h%"==2 set/aLen+=1,m*=10
- :nend
- set "fName=%strNum%%num1%.doc"
- if exist "%fName%" set n=%num1%&goto :nnext
- popd
- endlocal&set "%1=%fName%"
- goto :eof
复制代码
|