INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

List all mp3 files with bitrate and length properties?

List all mp3 files with bitrate and length properties?

List all mp3 files with bitrate and length properties?

(OP)
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 --> vbs

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 

RE: List all mp3 files with bitrate and length properties?

An illustrative example:

CODE

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 

RE: List all mp3 files with bitrate and length properties?

(OP)
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.

RE: List all mp3 files with bitrate and length properties?

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.

RE: List all mp3 files with bitrate and length properties?

(OP)
No worries. I'm going to have a play with it over the weekend and see what I can work out. Thank you.

RE: List all mp3 files with bitrate and length properties?

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

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 

RE: List all mp3 files with bitrate and length properties?

(OP)
Thank you Strongm I got it sorted now. Thank you for your help.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close