网上搜了下,发现这么常用的功能居然没有轮子,只好自己造了
@璐村惂鐢ㄦ埛_000076K馃惥 off
setlocal enabledelayedexpansion
set /p "位数=位数:"
echo,
set /p "补位字符=补位字符:"
echo,
:Loop
cls
set /p "dirValue=拖入文件夹(最好做备份):"
echo,
echo 请稍候...
for /r %dirValue% %%f in (*.*) do (
set "fileName=%%~nf"
call :PadLeft fileName 位数 补位字符
echo "%%~nf" =^> "!fileName!%%~xf"
ren "%%f" "!fileName!%%~xf"
)
echo 完成!
pause
goto :Loop
:GetStrLen <输入字符串> <输出字符串长度>
set len=0
set "tempStr=!%~1!"
if not defined %~1 goto :eof
:getStrLen_Loop
rem len+1
set /a %~2+=1
set "tempStr=!tempStr:~0,-1!"
if defined tempStr goto :getStrLen_Loop
goto :eof
:PadLeft <操作字符串> <位数> <补位字符>
call :GetStrLen %~1 len
if !len! GEQ !%~2! goto :eof
set /a len+=1
for /l %%a in (!len! 1 !%~2!) do (
set %~1=!%~3!!%~1!
)
goto :eof
@璐村惂鐢ㄦ埛_000076K馃惥 off
setlocal enabledelayedexpansion
set /p "位数=位数:"
echo,
set /p "补位字符=补位字符:"
echo,
:Loop
cls
set /p "dirValue=拖入文件夹(最好做备份):"
echo,
echo 请稍候...
for /r %dirValue% %%f in (*.*) do (
set "fileName=%%~nf"
call :PadLeft fileName 位数 补位字符
echo "%%~nf" =^> "!fileName!%%~xf"
ren "%%f" "!fileName!%%~xf"
)
echo 完成!
pause
goto :Loop
:GetStrLen <输入字符串> <输出字符串长度>
set len=0
set "tempStr=!%~1!"
if not defined %~1 goto :eof
:getStrLen_Loop
rem len+1
set /a %~2+=1
set "tempStr=!tempStr:~0,-1!"
if defined tempStr goto :getStrLen_Loop
goto :eof
:PadLeft <操作字符串> <位数> <补位字符>
call :GetStrLen %~1 len
if !len! GEQ !%~2! goto :eof
set /a len+=1
for /l %%a in (!len! 1 !%~2!) do (
set %~1=!%~3!!%~1!
)
goto :eof