I have a ton of mp3 files in different folders which are in the format below;
Track # - Song Name (Artist Name).mp3
ex. 01 - La Fille De Pekin (Frederick Rousseau).mp3
I wanted to rename all the files so I could import them easily using the following format;
Track # - Artist Name - Song Name.mp3
ex. 01 - Frederick Rousseau - La Fille De Pekin.mp3
This format helps me to adjust the meta data while importing. I wrote the following VBScript to rename the files in a directory :D
Option Explicit
On Error Resume Next
Dim a: a = WScript.Arguments.item(0)
Dim fso: Set fso=CreateObject("Scripting.FileSystemObject")
Dim lFolder: Set lFolder = fso.GetFolder(a)
Dim lFiles: Set lFiles = lFolder.Files
Dim lFile, numFiles
numFiles = 0
For each lFile in lFiles
RenameFile(lFile)
Next
Function RenameFile(fileObject)
Dim oldName, newName, fullnewName
Dim posDash, posParOpen, posParClose
Dim artistName, songName, trackNum
oldName = fileObject.Name
'get location of the dash
posDash = InStr(oldName, "-")
'get location of the first (
posParOpen = InStrRev(oldName,"(")
'get location of last )
posParClose = InStrRev(oldName, ")")
'get the track number
trackNum = Mid(oldName,1,posDash)
trackNum = Replace(trackNum,"-","")
trackNum = trim(trackNum)
'get the song name
songName = Mid(oldName,posDash,Cint(posParOpen - PosDash))
songName = Replace(songName,"-","")
songName = Trim(songName)
'get the artist name
artistName = Mid(oldName,posParOpen,Cint(posParClose - PosParOpen))
artistName = Replace(artistName,"(","")
artistName = Trim(artistName)
'new name formatted
newName = trackNum & " - " & artistName & " - " & songName & ".mp3"
fullNewName = fileObject.ParentFolder & "\" & newName
WSCript.Echo
WScript.Echo "Renaming.. " & fileObject.Name
WScript.Echo "To........ " & newName
'comment the following line to test it only.
fileObject.Move fullNewName
WScript.Echo
numFiles = numFiles + 1
End Function
WScript.Echo "Total Files Modified: " & numFiles
Set fso = Nothing
Set lFolder = Nothing
Set lFiles = Nothing
All you have to do to use it is copy paste into a vbs file "reformat.vbs" for example. Then run it using the command line:
C:\> cscript reformat.vbs "C:\Music\Some Messed up Album\"
Here is a link to the script, if you wish to download it. Just rename the file.
Link:
Reformat.txt