本帖最后由 求知路漫漫 于 2022-3-13 02:06 编辑
- @echo on
- set oldname=?
- set newname=?
- set num=0
- setlocal enabledelayedexpansion
- for /f "delims=" %%a in ('dir /a-d /s /b "%~1"') do (
- set f=%%~a
- set h=%%~xa
- set d=%%~dpa
- set s=%%~pa
- set s=!s:~0,-1!
- call :t "!s!"
- :here
- echo.
- (if "!newname!" equ "!oldnanme!" (
- :rename1
- set /a num+=1
- if exist "!d!!newname!!num!!h!" (call :rename1) else (
- ren "!f!" "!newname!!num!!h!"
- )
- ) else (
- set /a num=0
- :rename2
- set /a num+=1
- if exist "!d!!newname!!num!!h!" (call :rename2 ) else (
- ren "!f!" "!newname!!num!!h!"
- set "oldname=!newname!"
- )
- )
- )
- )
- goto :eof
-
- :t
- set "newname=%~n1"
- goto :eof
复制代码
|