Get MP3 Duration
Posed on 2009-07-27 00:09:38
Author: Gareth Bennett
I am very glad to get this script working as I have been working on it all night. The script will read a directory full of MP3 files; and then output the filename and duration of each MP3 file into a CSV file.
The only thing you have to change in the script is the Path and File names. You obviously don't want your output file in the same folder as your MP3 files; as it will not be able to read the duration property of the CVS file.
Option Explicit
Const OPENFORREADING = 1
Const OPENFORWRITING = 2
Const OPENFORAPPENDING = 8
Const DURATION = 21
Public Sub CreateMp3TrackList()
Dim objFSO, objFile, objTxtStream, objFsoFolder, objFiles
Dim objShell, objShellFolder, objFolderItem
Dim strFolder, strOutputFile, strTime, strName, strFileInfo, strGroup
strFolder = "D:\MP3Files"
strOutputFile = "D:\mp3list.csv"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Shell.Application")
Set objShellFolder = objShell.Namespace(strFolder)
Set objFsoFolder = objFSO.GetFolder(strFolder)
Set objFiles = objFsoFolder.Files
Set objFsoFolder = nothing
Set objTxtStream = objFSO.CreateTextFile(strOutputFile, True)
For Each objFile in objFiles
Set objFolderItem = objShellFolder.ParseName(objFile.Name)
strFileInfo = objShellFolder.GetDetailsOf(objFolderItem, DURATION)
strName = objFile.Name
strGroup = strName & "," & strFileInfo
objTxtStream.WriteLine strGroup
Set objFolderItem = nothing
Next
objTxtStream.Close
Set objFile = Nothing
Set objFiles = Nothing
Set objTxtStream = Nothing
Set objShellFolder = Nothing
Set objShell = Nothing
Set objFSO = Nothing
MsgBox "Completed"
End Sub
CreateMp3TrackList()