Solved

Mass rename of files

Posted on 2007-03-19
6
252 Views
Last Modified: 2010-05-18
I have about 3000 files entitled *_copy.mp3, where the * is the song name. I want to rename all these by removing the "_copy" portion of the name.

thisisasong_copy.mp3 would become thisisasong.mp3

Can you suggest an efficient way to do this?

Thanks!
JohnD

0
Comment
Question by:johndarby
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 1

Author Comment

by:johndarby
ID: 18754123
This is the VBScript I have thus far...

Dim filesys, file, folderName, folderObj, fileColl, objRegEx, newFile

Set filesys = CreateObject("Scripting.FileSystemObject")

folderName = InputBox("", "Folder Name")

Set folderObj = filesys.GetFolder(folderName)

Set fileColl = folderObj.Files

Set objRegEx = New RegExp
objRegEx.Pattern = "_copy"     ' looking for this

For Each objFile In fileColl
  newFile = objRegEx.Replace(objFile.Name, "")     ' replacing with this
  filesys.MoveFile objFile, folderName & "\" & newFile
Next
0
 
LVL 70

Expert Comment

by:Merete
ID: 18754656
johndarby
*_copy.mp3<< if your files have this name it maybe the results of a chkdsk detecting multiple copies of the same files.
Duplicate Checker is a powerful tool for finding duplicate images, mp3s and any other file types. Using this utility you can organize files on your hard disk or server storage.
http://www.duplicatechecker.com/

HOW TO: Rename Multiple Files in Windows XP with Windows Explorer
http://support.microsoft.com/kb/320167
http://www.codeproject.com/useritems/FileTreeCtrl.asp

File Renaming Tools
http://www.snapfiles.com/Freeware/system/fwfilerename.html

Just ideas
cheers M

0
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 18755217
Taking the script you've started...no regex really needed - use the replace function...

Dim filesys, file, folderName, folderObj, fileColl, objRegEx, newFile
Set filesys = CreateObject("Scripting.FileSystemObject")
folderName = InputBox("", "Folder Name")
'Make sure there's a trailing slash
If Right(folderName, 1) <> "\" Then folderName = folderName & "\"
Set folderObj = filesys.GetFolder(folderName)

For Each file In folderObj.Files
  If InStr(file.Name, "_copy") > 0 Then 'Only process files that have _copy
    filesys.MoveFile file.Path, Replace(file.Path, "_copy", "")
  End If
Next
0
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 
LVL 1

Author Comment

by:johndarby
ID: 18758726
As per usual, you rock, SB!
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18758817
Happy to help - thanx for the grade! :^)
0
 
LVL 1

Author Comment

by:johndarby
ID: 18760922
Sirbounty, what instruction do I add to make the name change recurse through subdirectories?
Thanks!
JohnD
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
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…

724 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