Windows Scripting
  Home arrow Windows Scripting arrow Page 2 - 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 - Creating the database


    (Page 2 of 4 )

    At this point we need to write the code that determines whether or not the database file exists and then creates it in the event that it doesn’t.

    strConnection = "Provider=Microsoft.Jet.OLEDB.4.0; " _

       & "Data Source=" & strDatabase & ""

    We’ll start by creating our database connection string.  We’re going to use Microsoft’s Jet driver to create and access our database.  I’ve chosen this driver because it is compatible with Access databases and because it is available natively.  You could use any other driver you choose, or even DSN, to create and manage your database.  The Jet driver just provides a nice level of simplicity and availability.

    If Not objFso.FileExists(strDatabase) Then

    At this point, we’re going to begin an If statement.  This statement uses the FileSystemObject to determine whether or not the database file exists.  If it doesn’t, it will execute the code inside the If statement before continuing.  In this case, that code will be used to create our database.

       Set objCatalog = CreateObject("ADOX.Catalog")

       objCatalog.Create strConnection

       Set objCatalog = Nothing

    This is the code used to create the database.  Notice that we’re using the connection string that we specified earlier.  You should also note that I’ve intentionally released the catalog object in the last line.  I’ve done this so that the database file will not be in use as we continue.

       Set oConn = CreateObject("ADODB.Connection")

       oConn.Open strConnection

    Next, we’ll use ADODB to open the database we’ve created.  This database is empty and has no structure, so the next logical step is to create a table in which to store our data.

       oConn.Execute "CREATE TABLE MP3Table(" _

           & "[Name] TEXT(255), " _

           & "[Title] TEXT(255), " _

           & "[Artist] TEXT(255), " _

           & "[AlbumTitle] TEXT(255), " _

           & "[Year] TEXT(25), " _

           & "[TrackNumber] TEXT(25), " _

           & "[Genre] TEXT(255), " _

           & "[Duration] TEXT(255), " _

           & "[Size] TEXT(255), " _

           & "[BitRate] TEXT(255), " _

           & "[Comments] MEMO)"

    We use the ADODB Connection object’s Execute method to execute a line of SQL code that creates the MP3Table table in our database.  We’re also specifying each of the fields to create within the table.  These match the data that we’ll be collecting from the ID3 tags on our MP3 files.

    You’ll also notice that I’ve kept the field names in square brackets.  This is because several of my field names are considered reserved keywords by Microsoft Access.  Enclosing them in square brackets will avoid errors when this query is executed.  For uniformity, I carried this practice for each of my fields.

       oConn.Close

       Set oConn = Nothing

    End If

    The code needed to create our database is complete, so we can close the database connection, release the object and close our If statement.

    More Windows Scripting Articles
    More By Nilpo


       · 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 5 hosted by Hostway
    Stay green...Green IT