VB Script to rename mp3 files

Insane_ai

Not Really an A.I.
Local time
Today, 05:16
Joined
Mar 20, 2009
Messages
264
This isn't related to Access but I like to share code when I come up with it. Feel free to use this.

I have been downloading music from the internet but the albums come packed with the artist name and track number built into the filename. This annoys me and manually renaming files gets old quick. This script takes the title from the metadata and renames the file accordingly while maintaining the original file extension.

[Begin Script]

Set fso = CreateObject("Scripting.FileSystemObject")
set oFldr = fso.getfolder(inputbox("Enter complete folder path"))
Dim strString(127)
Dim strTitle
Dim strExt
Dim strNewTitle
for each ofile in oFldr.Files
strTitle = ""
filename = ofile.name
'msgbox "FileName: " & filename
Set MpFile = fso.OpenTextFile(ofldr & "\" & filename, 1, False, 0)
sBuffer = MpFile.ReadAll
For i = 0 To 124
strString(i) = Chr(Asc(right(sBuffer, i + 1)))
Next

For x = 0 To 124
c = 124 - x
If c > 94 and c <= 127 Then
strTitle = strTitle & strString(c)
End If
Next

MpFile.Close
strExt = lcase(fso.GetExtensionName(ofile.Name))
strNewTitle = strTitle
ofile.Name = strNewTitle
ofile.name = ofile.name & "." & strExt


Next



[End Script]
 

Users who are viewing this thread

Back
Top Bottom