批处理文件仅用于大写所有文件夹的第一个字母

时间:2018-02-18 02:11:40

标签: batch-file directory uppercase batch-rename

james_doe-badly_written_songs_(edm_remixes)-web拉克-2018

James_Doe-Badly_Written_Song_(Edm_Remixes) - 网页拉克-2018

如果可能但不是nessassary

james doe - 写得很糟糕的歌曲(edm remixes)

詹姆斯·多伊 - 写得很糟糕的歌曲(Edm Remixes)

我试过这个我发现了,但它把所有的信都变成了大写

@echo off
setlocal disableDelayedExpansion
echo Renaming folders
for /d %%F in (C:\x\*) do (
  for /f "eol= " %%A in ("%%~nxF") do (
    set "name=%%F"
    set "newName=%%A"
    setlocal enableDelayedExpansion
    for %%C 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 "newName=!newName:%%C=%%C!"
    ren "!name!" "!newName!"
    endlocal
  )
)

感谢您的时间!

1 个答案:

答案 0 :(得分:1)

@ECHO OFF
SET String=Hello, how are you ?
SET String
CALL :TCase String
SET String
CALL :UpCase String
SET String
CALL :LoCase String
SET String
GOTO:EOF

:LoCase
rem Subroutine to convert a variable VALUE to all lower case.
rem The argument for this subroutine is the variable NAME.
FOR %%i IN ("A=a" "B=b" "C=c" "D=d" "E=e" "F=f" "G=g" "H=h" "I=i" "J=j" "K=k" "L=l" "M=m" "N=n" "O=o" "P=p" "Q=q" "R=r" "S=s" "T=t" "U=u" "V=v" "W=w" "X=x" "Y=y" "Z=z") DO CALL SET "%1=%%%1:%%~i%%"
GOTO:EOF

:UpCase
rem Subroutine to convert a variable VALUE to all UPPER CASE.
rem The argument for this subroutine is the variable NAME.
FOR %%i IN ("a=A" "b=B" "c=C" "d=D" "e=E" "f=F" "g=G" "h=H" "i=I" "j=J" "k=K" "l=L" "m=M" "n=N" "o=O" "p=P" "q=Q" "r=R" "s=S" "t=T" "u=U" "v=V" "w=W" "x=X" "y=Y" "z=Z") DO CALL SET "%1=%%%1:%%~i%%"
GOTO:EOF

:TCase
rem Subroutine to convert a variable VALUE to Title Case.
rem The argument for this subroutine is the variable NAME.
FOR %%i IN (" a= A" " b= B" " c= C" " d= D" " e= E" " f= F" " g= G" " h= H" " i= I" " j= J" " k= K" " l= L" " m= M" " n= N" " o= O" " p= P" " q= Q" " r= R" " s= S" " t= T" " u= U" " v= V" " w= W" " x= X" " y= Y" " z= Z") DO CALL SET "%1=%%%1:%%~i%%"
GOTO:EOF