1

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?

- 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".

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
VECHIN
  • 13
  • 1
  • 1
  • 4
  • Have you looked at http://stackoverflow.com/questions/717171/recursive-renaming-file-names-folder-names-with-a-batch-file – Ali Apr 23 '13 at 06:18

4 Answers4

1
@echo off
for /D %%d in (*) do (
   ren "%%d\File*_EN.txt" "File*_ENU.txt"
)
Aacini
  • 65,180
  • 12
  • 72
  • 108
0

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.

ElektroStudios
  • 19,105
  • 33
  • 200
  • 417
0

Try this:

ren folder1\file*.txt file*_enu.txt
ren folder2\file*.txt file*_enu.txt
Endoro
  • 37,015
  • 8
  • 50
  • 63
  • Your method works only if the new name is larger than the original. If the new name is shorter, it fails... – Aacini Apr 23 '13 at 15:19
  • I always post solutions for a specific question of an OP. Batch as a scripting language can never answer to all thinkable issues of a case.[How did wildcards work in MS-DOS?](http://blogs.msdn.com/b/oldnewthing/archive/2007/12/17/6785519.aspx) AND this also works: `ren file*.txt file*e.txt`, new filenames are `file?_e.txt`. – Endoro Apr 23 '13 at 16:40
  • 2
    Yes, I used to do the same :) My comment is not a criticism of your answer, but an explanatory note if someone think they may use the same method for a new shorter name... – Aacini Apr 23 '13 at 22:07
0

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
SbnSeebee
  • 64
  • 8