帮写个批处理命令

来源:百度知道 编辑:UC知道 时间:2024/06/24 09:14:26
比如我的电脑的某个文件夹里有若干文件,怎么重命名为01.扩展名,02.扩展名.....,

@echo off
setlocal enabledelayedexpansion
set n=1
for /f "delims=" %%i in ('dir /a-d /b *.txt') do (
ren "%%i" 0!n!.txt
set /a n+=1
)
pause

@echo off
for %%a in (*.txt) do call:mytest "%%a"

:mytest
rename %1 %random%.txt
当前目录下有N个txt文件,需要产生随机数,
让每一个文件都重命名为随机数命名,后缀不变.

@echo off
for /f "delims=" %%i in ('dir /a-d /b *.txt^|findstr /v "^[0-9]*\.txt$"') do call :ren_ "%%i"
pause
exit

:ren_
ren %1 %random%.txt 2>nul||goto ren_
goto :eof

以上代码能把当前目录下的txt文件更名为1~32767之间的文件名,对已经更名过的文件不再处理,可以试一下: