- @echo off&setlocal enabledelayedexpansion
- set "Name=随机标题.txt"
- for /f "delims=" %%a in (%Name%) do set /a n+=1&set ".!n!=%%a"
- for /f "delims=" %%a in ('dir /b *.txt') do (
- if /i not "%%a"=="%Name%" (
- set /a r=1+!random! %% n
- for %%b in (!r!) do ren "%%a" "!.%%b!%%a"
- )
- )
- pause
复制代码 假设需要改名的文档位于D:\abc目录,就将代码保存为bat放到D:\abc目录下,"随机标题.txt"也放到D:\abc目录下。 |