Batch file to rename files in multiple folders

纵然是瞬间 提交于 2019-12-11 10:11:20

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!