@echo off
setlocal enabledelayedexpansion
call :%* 2>nul || goto choice
goto :eof
:choice
set /p aa=安装右键菜单A,卸载右键菜单X:
if %aa%==a goto :install
if %aa%==x (goto :uninstall)else goto :choice
goto :eof
:resume
cd /d "%~1"
if not exist 重命名列表.txt (echo 这个文件夹里没有“重命名列表.txt”,无法恢复&pause&goto :eof)
del 临时.txt 2>nul
for /F "tokens=1* delims=:" %%i in ('findstr /n .* 重命名列表.txt') do set "line=%%i" &set "num%%i=%%j"
for /L %%i in (!line!,-1,1) do (>> 临时.txt echo.!num%%i!)
for /f "tokens=1,2 delims=^|" %%c in (临时.txt) do (ren %%d %%c)
del 临时.txt
goto :eof
:renam
cd /d "%~1"
if exist 重命名列表.txt echo 当前文件夹下已存在一个重命名列表,再次重命名会导致原文件名列表的丢失,如要重命名先手动删除这个文件夹下的“重命名列表.txt”,这样较为稳妥&pause&goto :eof
set /p nn=请输入随机字母的位数:
for %%b in (*.*) do (
if "%%~nxb"=="重命名列表.txt" goto :eof
call :ranwd2
ren %%~nxb !filename!%%~xb
echo %%~nxb^|!filename!%%~xb >>重命名列表.txt
)
goto :eof
:ranwd2
set word=
for /l %%a in (1,1,%nn%) do (call :ranwd1)
if not exist %word%.* (set filename=%word%) else call :ranwd2
goto :eof
:ranwd1
call :ranltr
set word=%word%%letter%
goto :eof
:ranltr
set letter=0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
set /a num=%random%%%62
call set letter=!letter:~%num%,1!
goto :eof
:install
reg add "hkcr\directory\shell\文件夹内文件随机字母重命名\command" /f /t reg_sz /v "" /d "\"%~0\" renam \"%%1\""
reg add "hkcr\directory\shell\反重命名\command" /f /t reg_sz /v "" /d "\"%~0\" resume \"%%1\""
goto :eof
:uninstall
reg delete "hkcr\directory\shell\反重命名" /f
reg delete "hkcr\directory\shell\文件夹内文件随机字母重命名" /f
goto :eof
我对2000多个文件测试成功,不满意的话再回帖