- @echo off
-
- rem 提示用户输入要替换的字符串和新的字符串
- set /p originText=请输入要替换的字符串:
- set /p newText=请输入新的字符串:
-
- rem 遍历当前目录及其子目录中的所有文件
- for /r %%f in (*%originText%*) do (
- set "filePath=%%f"
- set "fileName=%%~nxf"
- set "fileDir=%%~dpf"
- setlocal enabledelayedexpansion
- set "newFileName=!fileName:%originText%=%newText%!"
- ren "!filePath!" "!fileDir!!newFileName!"
- endlocal
- )
-
- echo 替换完成!
- pause
复制代码
|