Retrieving Extended File Properties
Microsoft® Windows® 2000 Scripting Guide
When you right-click a file in Windows Explorer and select Properties from the shortcut menu, a dialog box displays basic properties for that file, including such things as file name, file size, and the file creation, last access, and last modification dates. In addition to these basic properties, the Windows operating system also tracks a number of extended file properties. These properties are typically hidden; to display them in Windows Explorer, you must click View, click Choose Details, and then select the desired properties from the resulting dialog box (shown in Figure 11.7).
Figure 11.7 Choose Details Dialog Box
The Shell FolderItems object includes a GetDetailsOf method that allows you to access these extended properties. These properties, and their associated index numbers, are shown in Table 11.10.
Table 11.10 Retrieving Extended File Properties
Index |
Property |
Index |
Property |
---|---|---|---|
0 |
Name |
18 |
Year |
1 |
Size |
19 |
Track Number |
2 |
Type |
20 |
Genre |
3 |
Date Modified |
21 |
Duration |
4 |
Date Created |
22 |
Bit Rate |
5 |
Date Accessed |
23 |
Protected |
6 |
Attributes |
24 |
Camera Model |
7 |
Status |
25 |
Date Picture Taken |
8 |
Owner |
26 |
Dimensions |
9 |
Author |
27 |
Not used |
10 |
Title |
28 |
Not used |
11 |
Subject |
29 |
Not used |
12 |
Category |
30 |
Company |
13 |
Pages |
31 |
Description |
14 |
Comments |
32 |
File Version |
15 |
Copyright |
33 |
Product Name |
16 |
Artist |
34 |
Product Version |
17 |
Album Title |
|
|
To access any one of these properties, call the GetDetailsOf method, passing two parameters: the name of the file and the index number of the property to be retrieved. For example, the following code snippet echoes the Duration property for a media file:
Wscript.Echo objFolder.GetDetailsOf(strFileName, 21)
Scripting Steps
Listing 11.18 contains a script that retrieves all the extended properties for each file in the folder C:\Scripts. To carry out this task, the script must perform the following steps:
Create a one-dimensional array named arrHeaders, and set the size to 35. This array is used to hold the names of the extended properties.
Create an instance of the Shell object.
Use the Namespace method to return a Folder object representing the folder where the files are stored. In Listing 11.18, that folder is C:\Scripts.
Create a For Next loop to return the names of the extended properties. Because the first extended property has the index number 0, the loop runs from 0 to 34.
Use the GetDetailsOf method to retrieve the names of all 35 extended properties.
For each file in the folder, set up another For-Next loop running from 0 to 34.
For each file, echo the property name, and use the GetDetailsOf method to retrieve and echo the property value.
Listing 11.18 Retrieving Extended File Properties
1 2 3 4 5 6 7 8 9 10 11 12 |
|