用批处理重命名文本文件名的代码
作者:
把目录下的所有文本文件改成有规则的,比如:1.txt 2.txt 3.txt
实现代码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