用批处理重命名文本文件名的代码
程序员文章站
2022-06-23 18:27:33
实现代码1@echo off&setlocal enabledelayedexpansion for /f "delims="&nb...
实现代码1
@echo off&setlocal enabledelayedexpansion
for /f "delims=" %%a in ('dir/b *.txt') do (
set /a n+=1
if not exist "!n!.txt" (ren "%%a" "!n!.txt") else call :loop "%%a"
)
pause&exit
:loop
set /a n+=1
if exist "!n!.txt" goto loop
ren "%~1" "!n!.txt"
goto :eof
@echo off&setlocal enabledelayedexpansion
for /f "delims=" %%a in ('dir/b *.txt') do (
set /a n+=1
if not exist "!n!.txt" (ren "%%a" "!n!.txt") else call :loop "%%a"
)
pause&exit
:loop
set /a n+=1
if exist "!n!.txt" goto loop
ren "%~1" "!n!.txt"
goto :eof