Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

List all mp3 files with bitrate and length properties?

Status
Not open for further replies.

TLM2408

Technical User
Nov 24, 2017
4
AU
Hello,

I have the vbscript below that lists all the mp3 files in the current directory and prints them to an html file. What I am trying to do is get the bitrate and lenght of each file as well. I have tried playing with objDir.GetDetailsOf, but I can't figure out how to make it work with the script I have. RFrom what I have found the attributes I'm after are 27 for length and 28 for bitrate. Any help would be greatly apperciated.

This is what I currently have minus the html.

Code:
Class clsApplication
    Property Get Path()
          Dim sTmp
          If IsObject(WScript) Then 
               'Windows Scripting Host
Path = left(WScript.ScriptFullName, InStr(WScript.ScriptFullName, WScript.ScriptName) -2)
path = Replace(Path, "\","/" )
         
          End If
    End Property
End Class
Dim App : Set App = New clsApplication 'use as App.Path


Dim ls, fsObj, fd, fs, fl, sfs, sf, tf, als, afd, afs, afl, asfs, asf, afsObj

    ' specify the file extensions to list
    dim fileTypes
    fileTypes = Array("mp3","flac","mogg","mid","wav")

    ls = ""
    Set fsObj = CreateObject("Scripting.FileSystemObject")
    Set fd = fsObj.GetFolder(".")
    Set afsObj = CreateObject("Scripting.FileSystemObject")
    Set afd = afsObj.GetFolder(".")
    set fs = fd.Files
    set afs = afd.Files
    
    ' list subfolders
    
    set asfs = afd.SubFolders
    For Each asf in asfs
        als = als & "<li><a href=""" & asf.name & chr(47) & "index.html" & chr(34) & " class=""focusable""" & Chr(62) & "<img src=""" & asf.name & "/front.jpg"" class=""coverthumb"" alt="""">" & asf.name & "</a></li>" & chr(10)
    Next

        For Each fl in fs
        ' check whether the extension matches 
        if arrayContains(fileTypes, fsObj.GetExtensionName(fl.name))then
    ls = ls & "<li><a href=""#""" & " data-src=""" & "file:///" & app.path & "/" &  fl.name & chr(34) & " class=""focusable""  data-sn-right=""#prev""" & Chr(62) & "<img src=""" & "file:///" & app.path & "/front.jpg"" " & "class=""coverthumb"" alt="""" " & Chr(62) & fl.name & "</a></li>" & chr(10)

        end if
    Next
    Set tf = fsObj.OpenTextFile("index.html", 2, True, False)


HTML HERE
    Set fsObj = Nothing

    function arrayContains (arr, val)            
        dim found
        found = false
        for i = 0 to ubound(arr)
            if arr(i) = val then    
                found = true
                exit for 
            end if
        next
        arrayContains = found            
    end function
 
An illustrative example:

Code:
[blue]Public Sub example(strFullPath)
    Dim lp
    Dim ShellFolderItem
    Dim shFolder
    Dim fso
    Dim ssfDesktop
    ssfDesktop = 0
    
    With CreateObject("Shell.Application")
        Set ShellFolderItem = .NameSpace(ssfDesktop).ParseName(strFullPath)
        Set shFolder = ShellFolderItem.Parent
    End With
        
    For lp = 0 To 255
        If shFolder.GetDetailsOf(ShellFolderItem.Name, lp) <> "" Then
            wscript.echo shFolder.GetDetailsOf(ShellFolderItem.Name, lp) & "(" & lp & ") = " & 

shFolder.GetDetailsOf(shFolder.ParseName(ShellFolderItem.Name), lp)
        End If
    Next

End Sub[/blue]
 
Thank you very much Strongm. I appreciate your time, unfortunately I don't know how to get this to work with the script I have in my first post with all the audio files in the same folder the script is in. I'm a bit of a vbscript newbie sorry. Also it looks like it gets all of the extended properties. I'm trying to get 27 and 28 only.
 
It is illustrative, not me writing you a solution ... it gets all the properties to show you all the properties that are available (and it is worth pointing out that different versions of Windows support different extended properties ...) - but you could clearly just pick out specific ones by setting lp equal to the values you wanted rather than looping through all the avilable ones.
 
No worries. I'm going to have a play with it over the weekend and see what I can work out. Thank you.
 
Here, have a minor rewrite, turned into a function. Feed it the full path to the file and specify what you'd like returned:

Code:
[blue]WantName=0
WantValue=1
WantBoth=2
	
WScript.Echo GetExtended("<your_path_to_file_here>", 10, WantBoth)

Public Function GetExtended(strFullPath, ExtendedProperty, Response)
    Dim Answer(2)
    Dim shFolderItem
    Dim ssfDesktop

    ssfDesktop = 0
    
    With CreateObject("Shell.Application")
        Set shFolderItem = .NameSpace(ssfDesktop).ParseName(strFullPath)
    End With

	With shFolderItem.Parent
		Answer(0)=.GetDetailsOf(shFolderItem.Name, ExtendedProperty)
		Answer(1)= .GetDetailsOf(shFolderItem, ExtendedProperty)
		Answer(2) = Answer(0) & "(" & ExtendedProperty & ") = " & Answer(1)
    End With
	GetExtended=Answer(Response)
End Function[/blue]
 
Thank you Strongm I got it sorted now. Thank you for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top