Windows Scripting
  Home arrow Windows Scripting arrow Page 4 - Using WSH to Catalog MP3 Files
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  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
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

Using WSH to Catalog MP3 Files
By: Nilpo
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-10-01

    Table of Contents:
  • Using WSH to Catalog MP3 Files
  • Creating the database
  • Updating the database
  • Finishing the script

  • 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


    Using WSH to Catalog MP3 Files - Finishing the script


    (Page 4 of 4 )

    As I noted in my last article, the column IDs that need to be read by the GetDetailsOf method will vary across different versions of Windows.  In order to maintain compatibility I’ve chosen to use the SetColIds subroutine to assign the proper column IDs to variables depending upon the current version of Windows.

    Sub SetColIds

       If GetOSVersion = "XP" Or GetOSVersion = "2003" Then

           intSize = 1

           intTitle = 10

           intComments = 14

           intArtist = 16

           intAlbumTitle = 17

           intYear = 18

           intTrack = 19

           intGenre = 20

           intDuration = 21

           intBitRate = 22

    We’ll begin by creating the subroutine structure.  This subroutine simply uses an If statement to assign variable values for each OS version.  Since Windows XP and Windows Server 2003 use the same column IDs, we can combine them into the same branch of our If statement using the Or operator.

       ElseIf GetOSVersion = "Vista" Then

           intSize = 1

           intTitle = 21

           intComments = 24

           intArtist = 13

           intAlbumTitle = 14

           intYear = 15

           intTrack = 27

           intGenre = 16

           intDuration = 36

           intBitRate = 28

       End If

    End Sub

    The Else branch is used to assign variable values that are compatible with Windows Vista.  Notice that both conditional statements rely on the result from a GetOSVersion function.  This is a custom function that we’ll need to create in order to determine the OS version.

    Function GetOSVersion

       strComputer = "."

       Set objWMIService = GetObject("winmgmts:" _

           & "{impersonationLevel=impersonate}!" & strComputer & "rootcimv2")

     

       Set colOperatingSystems = objWMIService.ExecQuery _

           ("Select * from Win32_OperatingSystem")

     

       For Each objOperatingSystem in colOperatingSystems

           strVersion = objOperatingSystem.Caption

           Exit For

       Next

     

       If InStr(strVersion, "2000") > 0 Then GetOSVersion = "2000"

       If InStr(strVersion, "XP") > 0 Then GetOSVersion = "XP"

       If InStr(strVersion, "2003") > 0 Then GetOSVersion = "2003"

       If InStr(strVersion, "Vista") > 0 Then GetOSVersion = "Vista"

    End Function

    The GetOSVersion function looks complicated, but it’s actually pretty simple if you break down the steps.  It begins by using WMI to poll the name of the operating system.  This is done by using the Caption property of the Win32_OperatingSystem class.  This class does return a collection of instances, so we have to use a For Each loop to process it properly.

    The Exit For statement ensures that the function only returns information for the first instance in a case where a system has multiple operating systems installed.  The first instance will be the first “bootable” operating system.

    Finally, a set of If statements is used to determine which operating system is being used.  VBScript’s InStr function searches the caption string for identifying information.  Once the version is determined, it is returned by the function as a short string.

    And that’s all there is to it.  You’ve just created a script that is capable of looking in a folder, finding any MP3 files, reading their ID3 tags, and then storing that information in an Access-compatible database.  By pointing this script to each of your music folders, you can use it to create a catalog of all your music files.

    You can use this database in any way you wish.  Perhaps you just want an easy way to maintain a music library.  Or maybe you have a large collection of music and you’re looking for a better way to manage it.  Whatever your need, this script should put you well in the direction you want to go. 

    How about a scripting challenge?  Can you think of a way to create an HTML application to serve as a GUI interface for managing your MP3 catalog?  You could have drop down boxes for artist selection and album names and have it return appropriate song titles.  Or, you could add a Browse… button that would allow you to select new folders for adding to your database.

    The possibilities are endless.  Experiment with this code and see what you can accomplish.  Until next time, keep coding!


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · If you read my last article, you learned how to read MP3 ID3 tags in WSH. Let's...
     

    WINDOWS SCRIPTING ARTICLES

    - 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...
    - Modifying XML Files in WSH
    - Reading XML Files in WSH
    - Visual Basic 2005 XML Programming Using XML ...
    - Creating an XML Document in WSH
    - Introducing Two-Way Data Binding using Silve...
    - Silverlight 2.0 Application Development with...
    - Burning Multisession CDs with IMAPI2 in WSH
    - Creating a Silverlight 2.0 Application that ...
    - Burning CDs with the IMAPI2 Control
    - Burning CDs in Windows XP with WSH

     
    Best Practices for Windows Vista Migration Presentation
    Dell and Microsoft recently held a series of face-to-face seminars entitled, &qu....

     
    Creating a Culture for Code Reuse
    If you oversee development teams you know that like it or not proprietary and ex....

     
    Keys to Web Application Acceleration: Advances in Delivery Systems
    Accelerate Web apps by up to 5x. Ensure significantly faster access to the Web a....

     
    Optimizing Application Monitoring
    Tired of finding out from your customers that you're offline? This white paper e....

     
    Solaris to Solaris Migration -- Migrating applications from Sun SPARC to Dell PowerEdge R900
    This comprehensive Migration Guide reviews the approach that Principled Technolo....

     




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