问题
I have the folder and file structure as given below. I am in need of a MS DOS batch file to rename the files in multiple folders. Can anyone please help out? TIA.
-Main Folder
-->Sub Folder1
--- File1_EN.txt
--- File2_EN.txt
--> Sub Folder2
--- File3_EN.txt
--- File4_EN.txt
I want to rename the suffix "EN" in file names to "ENU".
回答1:
@echo off
for /D %%d in (*) do (
ren "%%d\File*_EN.txt" "File*_ENU.txt"
)
回答2:
You can do it by this way:
@Echo OFF
Set "Folder=C:\Users\Administrador\Desktop\Nueva carpeta"
Set "Suffix=_EN"
Set "Replace=_ENU"
Set "RegEx=\".*%Suffix%\"$"
FOR /R "%Folder%" %%# in ("*") DO (
(Echo "%%~n#"| FINDSTR /I "%RegEx%" 1>NUL) && (
Set "NewFileName=%%~nx#"
Call Set "NewFileName=%%NewFileName:%Suffix%=%Replace%%%"
Call Echo [+] Renaming: "%%~nx#" "%%NewFileName%%"
Ren "%%#" "%%NewFileName%%"
)
)
Pause&Exit
The Findstr is to ensure the matched string is a suffix, is better than doing a substring or splitting the filename from "_" character to the right.
回答3:
Try this:
ren folder1\file*.txt file*_enu.txt
ren folder2\file*.txt file*_enu.txt
回答4:
If you want all child folders to be changed use:
for /f "delims=*" %a in ('dir File*_EN.txt /b /s') do ren "%a" File*_ENU.txt
来源:https://stackoverflow.com/questions/16162103/batch-file-to-rename-files-in-multiple-folders