Renaming multiple folders in Windows 7

An accidental folder renaming operation added the number "2" to all folders in a specific directory.  Example: documents 2 or clients 2 etc.  There are thousands of these folders, and thus we are looking for a simple way to remove the number "2" from all folder names.  Suggestions?

Thank you.
Who is Participating?
Look at the following link for the details:

I have modified the above batch file to meet your need. It will rename all folders with '2' any where in their name (beginning, middle or end).

@echo off
setlocal enableextensions
for /D %%f in (*) do call :process "%%f"
goto :eof

pushd "%~dp1"

set fn=%~nx1
set fn=%fn:2=%

ren "%~nx1" "%fn%"

goto :eof  

Open in new window

Download the attached file in a test directory.
Rename the file from "rename_folders_2.txt" to "rename_folders_2.bat"

*** once you rename it to .bat on you system, do not double click it to open it. It will run the program. ****

Create bunch of folders with name containing 2 at the end as it is in your situation.
Run the "rename_folders_2.bat" file from a command prompt and it should work for win 7 as well.
I have tested it on XP.
Before you do any such changes it is always a good idea to make a BACKUP.

if you like you can change the "@ECHO OFF"  to "@ECHO ON"  and save the file as .bat (make sure your file type is all and NOT .TXT if using notepad.

at location where you want to test it you can run the command by typing

C:\TEST\rename_folder_2.bat > rename_folder_results.txt

This will generate a log file where you can see how it processed all the rename commands and if there is an error you will be able to see it.

Looks like Metamorphose would work:

I tested this on an XP machine with no issues.
It goes back in days when window was not available, I use to use a tool called xtree. That had the functionality to do rename using wildcard. I'm not sure is xtree  is still available.

How ever you can do it by either using excel to create a rename command for each folder or use a batch script (old  DOS command) to rename all the files.

Are all these folders are at same location or in multiple nested folder structure ?
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

I recommend program called ReNamer. It's free for non commercial users. Here's the download link I use this program a lot and it's very useful. It doesn't need to be installed as it can be downloaded as an archive. To remove "2"'s you open ReNamer and click on add then a menu should open. After just click on Remove on left side of just opened menu. Then enter "2" you want removed or " 2" if you want spaces removed that you also don't want.Then just drag all files/folders to ReNamer. Click Preview and if satisfied with the result Rename.

Best Regards,

AnilData ManagerCommented:
To rename one folder the syntax is    ren filename2.   filename.     in dos and like niaz suggested an excel file would be used to produce all the commands even if there are thousands it should work.

Assuming you got several levels of folders


dir *2 /b /a:d /s

To generate a list of all folders affected. Run the command at the root of the folder. Then use excel to generate commands like

ren c:\a\filename2.   c:\a\filename.
ren c:\a\filename2.   c:\a\filename.
ren c:\a\filename2.   c:\a\filename.
ren c:\b\filename2.   c:\b\filename.
ren c:\b\filename2.   c:\b\filename.

Export as a batch file and run it.

Please test on a couple of folders!

If you did not reboot. Ctrl + Z
thenightlifeAuthor Commented:
akajohn, I have all the folder names exported into an excel spreadsheet.  I did not have to do the sub-directories, so I removed the /s...thank goodness its only the root.  So, an example of one folder name that needs to be changed (on a mapped Y: drive)  Y:\Mus\View 2; I wish this name to be without the space and 2 (as well as the thousands of other folders).  Not sure how to approach it from your standpoint now?
AnilData ManagerCommented:

Attached spreadsheet:

Column B has examples of folders , all ending with a "2".

Column D is the command you need for renaming. After testing a few of those (copy paste it in a command line dos box in the folder Y:\MUS to test) copy the whole of column D in to a batch file and run it.
Fill down as many times as you need. You should paste the list of all affected folders in column B.

That should do the trick.
Hope this helps,


These are great solutions (some of which I may borrow and adapt to my environment), but it seems like a lot of work to go through in scripting this when Metamorphose  is freeware.
thenightlifeAuthor Commented:
Thank you niaz!  The batch file worked flawlessly.  An incredible post that will indeed assist many.  Also a big thank you to akajohn...the excel thing worked but was a bit more tedious to complete.

Again thank you very much.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.