来自C:\x\adrenaline_-_shut_the_fug_up_and_dance-2000
到C:\x\Adrenaline_-_Shut_The_Fug_Up_And_Dance-2000
我有这个代码,但它会把每一个字母都大写
@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
)
)
谢谢你!
答案 0 :(得分:0)
这次修改怎么样?我认为这可能会写得更简单。因此,请将此视为几个答案之一。
_
检索字母。并且_
后面的字母被转换为大写字母。反映上述观点的修改后的脚本如下:
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
ECHO Renaming folders
SET "DIR=C:\x\"
FOR /D %%F IN (%DIR%*) DO (
SET "BASENAME=%%~NXF"
SET "NAME=%%~NXF"
SET "F=TRUE"
SET "NEWNAME="
CALL :CONVERT
)
EXIT /B
:CONVERT
SET "L=!NAME:~0,1!"
IF %F% == TRUE (
SET "INITIAL=!L!"
FOR %%I 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 INITIAL=!INITIAL:%%I=%%I!
SET NEWNAME=!NEWNAME!!INITIAL!
) ELSE (
SET NEWNAME=!NEWNAME!!L!
)
IF !L! == _ (
SET "F=TRUE"
) ELSE (
SET "F=FALSE"
)
SET "NAME=!NAME:~1!"
IF DEFINED NAME GOTO CONVERT
IF NOT %DIR%!BASENAME! == %DIR%!NEWNAME! REN "%DIR%!BASENAME!" "!NEWNAME!"
EXIT /B
SET "DIR=C:\x\"
。_
,因为使用_
检索转换为大写字母的字母。如果我误解了你的问题,我很抱歉。