Using WSH to Catalog MP3 Files
(Page 1 of 4 )
In my last article I introduced you to a workaround that allows you to read MP3 ID3 tags in WSH. Today I’m going to show you how to create a database for cataloging those MP3 files.If you haven’t read “Reading MP3 ID3 Tags is WSH” you should go do that now. We’ll be building off the code created in that article. Without further ado, let’s get going.
strDatabase = "mp3catalog.mdb"
You’ll want to begin your script by specifying a database to use. It doesn’t have to exist. The script will check for the file and create it if it doesn’t. If it does, however, the script will instead update the existing database file.
Dim intSize, intTitle, intComments, intArtist, intAlbumTitle
Dim intYear, intTrack, intGenre, intDuration, intBitRate
Next, you’ll want to instantiate a few variables that will be used to hold Column ID numbers. You won’t generally see me using the Dim statement in my code, but in this case it’s necessary.
As you may remember from my last article, the column IDs we’ll be using vary across different versions of Windows. I’ve created a subroutine that will check the currently running version of Windows and assign the correct column IDs accordingly. Since this is done as a subroutine, it’s important to instantiate the variables first so that they are available globally.
Call SetColIds
Now is a good time to call that subroutine so that our variables will have the proper values. We’ll create the subroutine here in a bit.
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder(0, _
"Please select a folder containing MP3 files.", 0)
Finally, we’ll instantiate the objects that we need. The FileSystemObject will be used to determine whether or not the database file exists. We use the Shell object and its BrowseForFolder method to display a dialog box for the user to select a folder to catalog. The script will find all MP3 files in the specified folder.
Next: Creating the database >>
More Windows Scripting Articles
More By Nilpo