我有多组文件[group-Fullcast,KingPin等...]遵循上述模式。我想在所有这些文件中用BZC和[5m]用HZC替换字符串[3m]替换字符串" Fullcast"与" Fllcst" ; "主销"与" KngPn" ; " Themecast"与#34; ThemaCst"等等.........使用单个蝙蝠文件。
我得到了答案,但只有一个字符串 - How to rename file by replacing substring using batch in Windows
我可以创建多个bat文件,但如何使用单个bat文件重命名? 注意:文件位于" D:\ Images \"我想从桌面[C:\ Documents and Settings \ XXX \ Desktop]
启动bat文件答案 0 :(得分:0)
您没有说出您的脚本将如何获取要操作的文件列表。此示例假定您正在查看当前目录中的所有文件。
@ECHO OFF
SETLOCAL
FOR %%i IN (*.jpg) DO CALL :CUSTOM_RENAME "%%~i"
FOR %%i IN (*.png) DO CALL :CUSTOM_RENAME "%%~i"
EXIT /B
:CUSTOM_RENAME
SETLOCAL ENABLEDELAYEDEXPANSION
FOR /F "delims=*" %%f IN ("%~1") DO (
SET "SOURCE=%%~f"
SET "NEWNAME=%%~nxf"
)
SET "NEWNAME=!NEWNAME:[3m]=BZC!"
SET "NEWNAME=!NEWNAME:[5m]=HZC!"
REM Other substitutions would go here, assuming they don't overlap.
@ECHO "!SOURCE!" --^> "!NEWNAME!"
rename "!SOURCE!" "!NEWNAME!"
ENDLOCAL
EXIT /B