Solved

Mass rename of files

Posted on 2007-03-19
6
251 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
Technology Partners: 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!

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

733 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