@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 not exist 重命名列表.txt goto :next
if exist 重命名列表.txt set /p aa=当前文件夹下已存在一个重命名
列表,再次重命名会导致原始文件名列表的丢失,如要继续请按A,如要
退出请按任意键:
if /i %aa%==a (goto :next) else goto :eof
:next
del 重命名列表.txt
set /p mm=请输入随机字母位数的上限值:
for %%b in (*.*) do (
if "%%~nxb"=="重命名列表.txt" goto :eof
call :ranwrd
if not exist %word%.* call :ranwrd
ren %%~nxb !word!%%~xb
echo %%~nxb^|!word!%%~xb >>重命名列表.txt
)
goto :eof
:ranwrd
set word=
set /a nn=%random%%%%mm%+1
for /l %%a in (1,1,%nn%) do (call :ranltr)
goto :eof
:ranltr
set
letter=0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRS
TUVWXYZ
set /a num=%random%%%62
call set letter=!letter:~%num%,1!
set word=%word%%letter%
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