@ECHO OFF
SETLOCAL EnableExtensions EnableDelayedExpansion
REM 0 = Rename the file randomly.
REM 1 = Prepend the existing file name with randomly generated string.
SET PrependOnly=0
REM 1 = Undo changes according to the translation file.
REM This will only work if the file "__Translation.txt" is in the same folder.
REM If you delete the translaction file, you will not be able to undo the changes!
SET Undo=0
SET TranslationFile=__Translation.txt
IF NOT {%Undo%}=={1} (
REM Rename files
ECHO 将要随机重命名以下文件夹中的每个文件:
ECHO %~dp0
ECHO.
ECHO 生成__Translation.txt备份文件
ECHO 输入OK继续
SET /P Confirm=
IF /I NOT {!Confirm!}=={OK} (
ECHO.
ECHO Aborting.
GOTO :EOF
)
ECHO 原名称/随机名称 > %TranslationFile%
ECHO ------------------------- >> %TranslationFile%
FOR /F "tokens=*" %%A IN ('DIR /A:-D /B') DO (
IF NOT %%A==%~nx0 (
IF NOT %%A==%TranslationFile% (
SET Use=%%~xA
IF {%PrependOnly%}=={1} SET Use=_%%A
SET NewName=!RANDOM!-!RANDOM!-!RANDOM!!Use!
ECHO %%A/!NewName!>> %TranslationFile%
RENAME "%%A" "!NewName!"
)
)
)
) ELSE (
ECHO Undo mode.
IF NOT EXIST %TranslationFile% (
ECHO Missing translation file: %TranslationFile%
PAUSE
GOTO :EOF
)
FOR /F "skip=2 tokens=1,2 delims=/" %%A IN (%TranslationFile%) DO RENAME "%%B" "%%A"
DEL /F /Q %TranslationFile%
)
会批量随机重命名 当前文件夹所有文件,注意新建个文件夹把文件和这个bat放到同一个目录, 为了误操作 需要输入 OK 回车才开始执行