Mp3 report

A friend, who uses Windows XP, asked me to provide her with a report with all the mp3 files she kept in a folder hierarchy. So, I wrote the following VB script, that produces a tab-delimited text file as the report, and places it on the desktop. The report can be opened in Excel.

Be careful when using this script, because, if a file with the same name as the report exists, it will be overwritten! Before running the script, change the name of the initial folder from where you want the search to begin. When the report finishes, a message box will pop up.

'This VB script creates a report for mp3 files.
'The report is a tab-delimited text file named "Full Mp3 Report.txt" and is created in the user's desktop.
'The user can open the report file in Excel.
'The variable strInitialFolder must be set to the folder down from where the search will begin.
'When the report is ready, a message box will pop up.

Option Explicit

Dim objShell
Dim objFSO
Dim objReportFile
Dim strInitialFolder
Dim intPosition
Dim strHeader

set objShell = CreateObject("Shell.Application")
Set objFSO = CreateObject("Scripting.FileSystemObject")

'The report will be created in the desktop as "Full Mp3 Report.txt".
'Be careful! If a file with that name already exists, it will be overwritten!
Set objReportFile = objFSO.CreateTextFile(CreateObject("WScript.Shell").ExpandEnvironmentStrings("%userprofile%\Desktop\Full Mp3 Report.txt"), True)

'Change strInitialFolder to the folder from down on where you keep your mp3 files.
'Do not forget to include a trailing backslash, as in the following examples:
'Possible values are "C:\", "D:\", "C:\SomeFolder\", "D:\SomeFolder\", "E:\SomeFolder\SomeOtherFolder\", etc.
strInitialFolder = "E:\Music\"

'intPosition contains the position in the path string from which the path to each particular mp3 file will be reported.
'This is done to provide a useful feature to the user, which is to omit from each path the initial folder string,
'and thus report only a relative (to the initial folder) path.
intPosition = len(strInitialFolder) + 1

strHeader =                     "Artist"
strHeader = strHeader & vbTab & "Album"
strHeader = strHeader & vbTab & "Name"
strHeader = strHeader & vbTab & "Title"
strHeader = strHeader & vbTab & "Year"
strHeader = strHeader & vbTab & "Genre"
strHeader = strHeader & vbTab & "Track No."
strHeader = strHeader & vbTab & "Path"
strHeader = strHeader & vbTab & "Size"
strHeader = strHeader & vbTab & "Duration"
strHeader = strHeader & vbTab & "Bit Rate"
strHeader = strHeader & vbTab & "Date Modified"
strHeader = strHeader & vbTab & "Date Created"
strHeader = strHeader & vbTab & "Date Accessed"
strHeader = strHeader & vbTab & "Attributes"
strHeader = strHeader & vbTab & "Protected"
strHeader = strHeader & vbTab & "Audio Sample Size"
strHeader = strHeader & vbTab & "Audio Sample Rate"
strHeader = strHeader & vbTab & "Channels"

objReportFile.WriteLine strHeader

ProcessFolder objFSO.GetFolder(strInitialFolder)
MsgBox "The report is ready." & vbCr & "You will find it in the file" & vbCr & "Full Mp3 Report.txt."

'Subroutine for recursive folder access
Sub ProcessFolder(objCurrentFolder)
   Dim strSearch
   Dim strTemp
   Dim strOutput
   Dim objFolder  
   Dim objFile
   Dim objSubFolder

   strSearch = ".mp3"

   Set objFolder = objShell.NameSpace(objCurrentFolder.Path)  

   For Each objFile In objFolder.Items
      strTemp = Right(objFile.Name, 4)
          
      If UCase(strTemp) = UCase(strSearch) Then    
         strOutput =                     objFolder.GetDetailsOf(objFile,16)      'Artist
         strOutput = strOutput & vbTab & objFolder.GetDetailsOf(objFile, 17)     'Album
         strOutput = strOutput & vbTab & objFile.Name                            'Name
         strOutput = strOutput & vbTab & objFolder.GetDetailsOf(objFile, 10)     'Title
         strOutput = strOutput & vbTab & objFolder.GetDetailsOf(objFile, 18)     'Year
         strOutput = strOutput & vbTab & objFolder.GetDetailsOf(objFile, 20)     'Genre
         strOutput = strOutput & vbTab & objFolder.GetDetailsOf(objFile, 19)     'Track No.
         strOutput = strOutput & vbTab & mid(objCurrentFolder.Path, intPosition) 'Path
         strOutput = strOutput & vbTab & objFolder.GetDetailsOf(objFile, 1)      'Size
         strOutput = strOutput & vbTab & objFolder.GetDetailsOf(objFile, 21)     'Duration
         strOutput = strOutput & vbTab & objFolder.GetDetailsOf(objFile, 22)     'Bit Rate
         strOutput = strOutput & vbTab & objFolder.GetDetailsOf(objFile, 3)      'Date Modified
         strOutput = strOutput & vbTab & objFolder.GetDetailsOf(objFile, 4)      'Date Created
         strOutput = strOutput & vbTab & objFolder.GetDetailsOf(objFile, 5)      'Date Accessed
         strOutput = strOutput & vbTab & objFolder.GetDetailsOf(objFile, 6)      'Attributes
         strOutput = strOutput & vbTab & objFolder.GetDetailsOf(objFile, 23)     'Protected
         strOutput = strOutput & vbTab & objFolder.GetDetailsOf(objFile, 32)     'Audio Sample Size
         strOutput = strOutput & vbTab & objFolder.GetDetailsOf(objFile, 33)     'Audio Sample Rate
         strOutput = strOutput & vbTab & objFolder.GetDetailsOf(objFile, 34)     'Channels

         objReportFile.writeline strOutput
      End If
   Next

   For Each objSubFolder In objCurrentFolder.SubFolders
      ProcessFolder objSubFolder
   Next      
End Sub
Advertisements

About Dimitrios Kalemis

I am a systems engineer specializing in Microsoft products and technologies. I am also an author. Please visit my blog to see the blog posts I have written, the books I have written and the applications I have created. I definitely recommend my blog posts under the category "Management", all my books and all my applications. I believe that you will find them interesting and useful. I am in the process of writing more blog posts and books, so please visit my blog from time to time to see what I come up with next. I am also active on other sites; links to those you can find in the "About me" page of my blog.
This entry was posted in Administration. Bookmark the permalink.