Solved

Mass rename of files

Posted on 2007-03-19
6
247 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 69

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

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

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
The password reset disk is often mentioned as the best solution to deal with the lost Windows password problem. In Windows 2008, 7, Vista and XP, a password reset disk can be easily created. But besides Windows 7/Vista/XP, Windows Server 2008 and ot…
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…
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). …

708 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

12 Experts available now in Live!

Get 1:1 Help Now