Renaming multiple folders in Windows 7

Posted on 2011-02-14
Last Modified: 2012-05-11
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.
Question by:thenightlife
  • 2
  • 2
  • 2
  • +3

Expert Comment

ID: 34889578
Looks like Metamorphose would work:

I tested this on an XP machine with no issues.

Expert Comment

ID: 34889645
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 ?

Expert Comment

ID: 34889799
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,

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!


Expert Comment

ID: 34889812
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!


Expert Comment

ID: 34891026
If you did not reboot. Ctrl + Z

Author Comment

ID: 34892793
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?

Expert Comment

ID: 34893200

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,



Accepted Solution

niaz earned 125 total points
ID: 34894172
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.


Expert Comment

ID: 34898510
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.

Author Comment

ID: 34902381
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.

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Log files are useful in diagnosing and repairing problems.  This is a list of common log files and their standard locations that I've compiled.   While this is not exhaustive, it is a pretty good list that I've found to be useful.  I may update it f…
Citrix XenApp, Internet Explorer 11 set to Enterprise Mode and using central hosted sites.xml file.
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question