Solved

Renaming multiple folders in Windows 7

Posted on 2011-02-14
10
612 Views
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.
0
Comment
Question by:thenightlife
  • 2
  • 2
  • 2
  • +3
10 Comments
 

Expert Comment

by:paul_mountcastle
ID: 34889578
Looks like Metamorphose would work:
http://file-folder-ren.sourceforge.net/

I tested this on an XP machine with no issues.
0
 
LVL 2

Expert Comment

by:niaz
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 ?
0
 
LVL 4

Expert Comment

by:florjan
ID: 34889799
I recommend program called ReNamer. It's free for non commercial users. Here's the download link
http://www.den4b.com/?x=downloads. 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,

Florjan
0
 
LVL 6

Expert Comment

by:akajohn
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


Use

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!


A>
0
 
LVL 5

Expert Comment

by:EnriquePhoenix
ID: 34891026
If you did not reboot. Ctrl + Z
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:thenightlife
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?
0
 
LVL 6

Expert Comment

by:akajohn
ID: 34893200
Hi,

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,


A>

rename-dos.xls
0
 
LVL 2

Accepted Solution

by:
niaz earned 125 total points
ID: 34894172
Look at the following link for the details:

http://stackoverflow.com/questions/717171/recursive-renaming-file-names-folder-names-with-a-batch-file

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"
endlocal
goto :eof

:process
pushd "%~dp1"

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

ren "%~nx1" "%fn%"

popd
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.
**** TEST IT THROUGHLY BEFORE YOU RUN****

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.


rename-folders-2.txt
rename-folder-results.txt.txt
0
 

Expert Comment

by:paul_mountcastle
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.
0
 

Author Comment

by:thenightlife
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.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In a hurry?.. scroll down to "HERE's HOW TO DO IT" Section. Greetings All, I was going to post this as question/solution, but its seems more appropriate as an article considering its length.  I felt it important to illucidate all the details c…
This article covers how to install the Microsoft Windows Operating System (OS). What is covered in this article:  > Different Versions and Editions of the Windows OS  > Upgrading versus Fresh Installation of the OS           - Steps to take pr…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now