Windows Scripting
  Home arrow Windows Scripting arrow Page 3 - 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 - Updating the database


    (Page 3 of 4 )

    When I created the code to be used in this article, I wanted it to remain expandable.  To truly automate this process, I believe that the code should be easily modified to support multiple folders and folders containing multiple file types.

    If Not objFolder Is Nothing Then

    This line of code checks to make sure that we’re using a valid folder object.  When the code uses the BrowseForFolder method as I’ve shown, this should never be a problem.  However, if this code is modified to support multiple folders or folder recursion, it is possible that it could try to run against a folder that doesn’t exist.  This line simply prevents errors by making sure that doesn’t happen.

       Set colFiles = objFolder.Items

    Suppose that we have a valid Folder object. We need to use its Items property to return a collection of File objects representing the files in that folder.  We’ll create a For Each loop to iterate through the collection and process each of the files.

       Set oConn = CreateObject("ADODB.Connection")

       oConn.Open strConnection

       Set objRs = CreateObject("ADODB.Recordset")

       objRs.Open "SELECT * FROM MP3Table", oConn, 0, 3

    Before we get into the processing of our collection of File objects, we need to reopen a connection to our database.  I’ve chosen to open a connection here, because a connection will not be available at this point in the script if the database already exists when the script is run.  I’m also creating a record set so that we can update the data in our database.

       For Each objFile In colFiles

           strType = objFolder.GetDetailsOf(objFile, 2)

           If strType = "MP3 Format Sound" Then

    Now we can create the For Each loop that will process our files.  I’ve also gone a step further to check the file’s type.  An If statement is used to ensure that the commands that follow are only executed for MP3 files.  This effectively filters the files in our collection in case a folder contains files other than MP3s.

    You might wonder why I haven’t included any code to determine whether or not the folder actually does contain MP3 files.  You certainly could, but it’s really not necessary.  If there are no files in the folder, the colFiles collection with simply be empty.  A For Each statement will not cause an error if it is executed against an empty collection.  It will simply continue without executing the loop.

              objRs.AddNew

              objRs("Name") = objFile.Name & ".mp3"

              objRs("Size") = objFolder.GetDetailsOf(objFile, intSize)

              objRs("Title") = objFolder.GetDetailsOf(objFile, intTitle)

              objRs("Comments") = objFolder.GetDetailsOf(objFile, intComments)

              objRs("Artist") = objFolder.GetDetailsOf(objFile, intArtist)

              objRs("AlbumTitle") = objFolder.GetDetailsOf(objFile, intAlbumTitle)

              objRs("Year") = objFolder.GetDetailsOf(objFile, intYear)

              objRs("TrackNumber") = objFolder.GetDetailsOf(objFile, intTrack)

              objRs("Genre") = objFolder.GetDetailsOf(objFile, intGenre)

              objRs("Duration") = objFolder.GetDetailsOf(objFile, intDuration)

              objRs("BitRate") = objFolder.GetDetailsOf(objFile, intBitRate)

              objRs.Update

    Now as we iterate through the files, we update our database with the information that is read from the MP3 files.  This is based off the code that was presented in my last article.  It uses the Folder object’s GetDetailsOf method to read the details of each file and adds that data to the record set.  That record set is then used to update the database.

           End If

       Next

       objRs.Close

    End If

     

    oConn.Close

    With all of the work done, we can close all of our structures.  Don’t forget to include the lines that close the record set and the database connection.

    We’ve now added all of the information that was gathered from the MP3 files to the database that we’ve created.  Now let’s create the supporting subroutine and function that we’ll need to make this script usable.

    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