BAT 批量替换文件名指定文字

下面的例子是把文件名中的A100变成C100,B100变成D100。

@echo off
Setlocal enabledelayedexpansion

Set "BeforeStr=A100"
Set "AfterStr=C100"

For /r %%# in (*) Do (
    Set "File=%%~nx#"
    Ren "%%#" "!File:%BeforeStr%=%AfterStr%!"
)

Set "BeforeStr=B100"
Set "AfterStr=D100"
For /r %%# in (*) Do (
    Set "File=%%~nx#"
    Ren "%%#" "!File:%BeforeStr%=%AfterStr%!"
)

你可能感兴趣的:(BAT,BAT)