Reading MP3 ID3 Tags in WSH - Retrieving file details in WSH
(Page 2 of 4 )
As I mentioned, we’re going to rely on the Windows Shell and its scripting interface for retrieving the information we want. I’m going to tell you the column numbers you need to use later in this article, but for learning purposes, let’s see how I was able to find them.
strFolder = "C:Documents and SettingsNilpoMy DocumentsMy Music"
We begin our script by creating the variable strFolder and setting it to a folder path containing MP3 files.
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(strFolder)
Next we connect to the Windows Shell object and use its NameSpace method to return a folder object.
object.GetDetailsOf(file, colId)
The Folder object has a GetDetailsOf method that allows us to read the details of files within a folder. It has two required parameters where file is a reference to a File object within the folder and colId is an integer representing the detail column to read.
Ordinarily, at this point we would use the Folder object’s Items property to return a collection of File objects and then iterate through them, reading the respective details; but as it turns out, if you provide a non-existent object, you can return the actual column headings instead.
For N = 0 To 100
WScript.Echo N & vbTab & objFolder.GetDetailsOf(Nothing, N)
Next
Depending upon your system and the types of files contained in the folder, there can be well over one hundred different file properties available. For our purposes we’re only going to look at the first one hundred.
Here, I’m using a simple For…Next loop count from 0 to 100. Notice that I’ve used the Nothing keyword in place of a File object in the first parameter. Remember that VBScript uses the Nothing keyword to represent a disconnected or invalid object reference.
Running the script will return a list of all of the column headings for columns 0 through 100. You can run this script on your own if you’re curious about the different details that are available, but I’ve included a table below with the ones that we are interested in.
Windows XP and Windows Server 2003 use the same column IDs while Vista has its own renumbering. Some of these fields are also available on Windows 2000 and earlier; however, they may not include all of them.
Tag Name | Windows XP and Windows Server 2003 | Windows Vista |
Name | 0 | 0 |
Size | 1 | 1 |
Type | 2 | 2 |
Title | 10 | 21 |
Comments | 14 | 24 |
Artist | 16 | 13 |
Album Title | 17 | 14 |
Year | 18 | 15 |
Track Number | 19 | 27 |
Genre | 20 | 16 |
Duration | 21 | 36 |
Bit Rate | 22 | 28 |
Next: Constructing the Script >>
More Windows Scripting Articles
More By Nilpo