批处理文件,怎么实现目录下文件或目录名中存在小写的字母时,统一改成大写?

如题所述

@echo off & title 转换文件(夹)名中小写为大写 By 依梦琴瑶
cd /d %~dp0
setlocal enabledelayedexpansion

for /f "delims=" %%a in ('dir /s/b') do (
    set "RelativePath=%%~a"
    set "RelativePath=!RelativePath:%~dp0=!
    call :Convert
)
pause
exit


:Convert
if not defined RelativePath goto :eof
if "!RelativePath:~-1!"=="\" set "RelativePath=!RelativePath:~,-1!"

for %%i in ("!RelativePath!") do (
    set "Name=%%~nxi"
    for %%j in (A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z) do (
        set "Name=!Name:%%~j=%%~j!"
    )
    ren "!RelativePath!" "!Name!"
    set "RelativePath=%%~dpi"
    set "RelativePath=!RelativePath:%~dp0=!
)
goto Convert

脚本放在哪个目录执行,那个目录下的所有文件或文件夹都会被转换。

温馨提示:答案为网友推荐,仅供参考
相似回答