更改批处理脚本以递归方式更改所有文件类型

时间:2016-08-27 14:31:37

标签: batch-file

我正在尝试修改下面的代码,以递归方式重命名所有子目录中的所有文件类型,而不仅仅是单一类型:

@echo off
Setlocal enabledelayedexpansion
Set "Pattern=rename"
Set "Replace=reuse"
For %%# in ("C:\Folder\*.jpg") Do (
Set "File=%%~nx#"
Ren "%%#" "!File:%Pattern%=%Replace%!"
)
Pause&Exit

来源: How to rename file by replacing substring using batch in Windows

非常感谢任何帮助!

1 个答案:

答案 0 :(得分:0)

尝试此修改,如果您发现结果符合预期,请在命令echo

之前摆脱Ren
@echo off
Setlocal enabledelayedexpansion
Set "Pattern=rename"
Set "Replace=reuse"
Set "MyFolder=%userprofile%\Desktop\test\*.*"
For %%# in ("%MyFolder%") Do (
    Set "File=%%~nx#"
    echo Ren "%%#" "!File:%Pattern%=%Replace%!"
)
Pause>nul & Exit