Solved

Mass rename of files

Posted on 2007-03-19
6
249 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
  • 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
Citrix XenApp, Internet Explorer 11 set to Enterprise Mode and using central hosted sites.xml file.
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…

776 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