Windows Scripting
  Home arrow Windows Scripting arrow Page 3 - Reading MP3 ID3 Tags in WSH
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WINDOWS SCRIPTING

Reading MP3 ID3 Tags in WSH
By: Nilpo
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2008-09-24

    Table of Contents:
  • Reading MP3 ID3 Tags in WSH
  • Retrieving file details in WSH
  • Constructing the Script
  • Working with the Data

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Reading MP3 ID3 Tags in WSH - Constructing the Script


    (Page 3 of 4 )

    Once you know the column ID for the detail information that you want, you can use the GetDetailsOf method to return that information.  You’re actual working script is going to begin much like the one we’ve just used.

    strFolder = "C:Documents and SettingsNilpoMy DocumentsMy Music"

     

    Set objShell = CreateObject("Shell.Application")

    Set objFolder = objShell.NameSpace(strFolder)

    Again, you’ll need to specify a folder to work with.  Then you’ll connect to the Windows Shell object and return a Folder object.

    Set colFiles = objFolder.Items

    Next, you’ll use the Folder object’s Items property to return a collection of File objects that are contained in the folder.  Now it’s just a matter of iterating through the collection.

    Because you may want to run this script against multiple folders or add recursive searching, I’m going to add a little bit of error-handling.

    If Not objFolder Is Nothing Then

    The remainder of the script is enclosed in this If statement. This will prevent any errors if the script attempts to load a folder path that doesn’t exist. In my case, I keep this script at all times to maintain a database of my MP3 library. From time to time, folders get moved or deleted. With this line in place, I don’t have to worry if I forget to update my script.

    For Each objFile In colFiles

       strType = objFolder.GetDetailsOf(objFile, 2)

       If strType = "MP3 Format Sound" Then

    Next, I’ll begin a For Each loop to iterate through the collection objects. This will process each file in our folder. Again, I’ve chosen to do a little extra work. I’m first using the GetDetailsOf method to determine the file type. Then I’m using an If statement to check that the file is an MP3. Including this If statement will allow the script to run on folders that contain additional files by filtering out the MP3s that we’re looking for.

           WScript.Echo "Name:", objFile.Name & ".mp3"

           WScript.Echo "Size:", objFolder.GetDetailsOf(objFile, 1)

           WScript.Echo "Title:", objFolder.GetDetailsOf(objFile, 10)

           WScript.Echo "Comments:", objFolder.GetDetailsOf(objFile, 14)

           WScript.Echo "Artist:", objFolder.GetDetailsOf(objFile, 16)

           WScript.Echo "Album Title:", objFolder.GetDetailsOf(objFile, 17)

           WScript.Echo "Year:", objFolder.GetDetailsOf(objFile, 18)

           WScript.Echo "Track Number:", objFolder.GetDetailsOf(objFile, 19)

           WScript.Echo "Genre:", objFolder.GetDetailsOf(objFile, 20)

           WScript.Echo "Duration:", objFolder.GetDetailsOf(objFile, 21)

           WScript.Echo "Bit Rate:", objFolder.GetDetailsOf(objFile, 22)

           WScript.Echo "**************************************************"

    Now it’s a simple matter of using the GetDetailsOf method to retrieve the file details associated with the ID3 fields. This example uses the column IDs for Windows XP and Windows Server 2003. If you are using Windows Vista, you should refer to the table on the last page and change the column IDs accordingly.

           End If

       Next

    End If

    We can wrap up the script by closing all of our statements.  Running the script will process each MP3 file in the folder that you’ve specified and print a list of details for each file.

    More Windows Scripting Articles
    More By Nilpo


       · Did you know that you can use WSH and the Windows Shell object to read the ID3...
       · What would be really usefull is a way to be able to add more tabs on the columns in...
       · There are some third-party ActiveX components available that can do this.
     

    WINDOWS SCRIPTING ARTICLES

    - More Windows Scripting Workarounds from Nilpo
    - Overloading Methods and More in VBScript
    - Improving MFC for Windows Vista
    - Regular Expressions in VBScript
    - Working with Dates in WMI
    - Completing Calendars with VBScript Date Func...
    - Building Calendars with VBScript Date Functi...
    - Working With Dates and Times in VBScript
    - Designing WCF DataContract Classes Using the...
    - Understanding Dates and Times in VBScript
    - Working With Arrays in VBScript
    - Compressed Folders in WSH
    - Using .NET Interops in VBScript
    - Nilpo`s Scripting Secrets, Vol I
    - Database operations using Silverlight 2.0 WC...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    Stay green...Green IT