Retrieving Extended File Properties

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

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

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

IndexPropertyIndexProperty
0    Name18Year
1Size19Track Number
2Type20Genre
3Date Modified21Duration
4Date Created22Bit Rate
5Date Accessed23Protected
6Attributes24Camera Model
7Status25Date Picture Taken
8Owner26Dimensions
9Author27Not used
10Title28Not used
11Subject29Not used
12Category30Company
13Pages31Description
14Comments32File Version
15Copyright33Product Name
16Artist34Product Version
17Album 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:

  1. 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.
  2. Create an instance of the Shell object.
  3. 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.
  4. 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.
  5. Use the GetDetailsOf method to retrieve the names of all 35 extended properties.
  6. For each file in the folder, set up another For-Next loop running from 0 to 34.
  7. 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 
Dim arrHeaders(35) Set objShell = CreateObject("Shell.Application") Set objFolder = objShell.Namespace("C:\Scripts") For i = 0 to 34     arrHeaders(i) = objFolder.GetDetailsOf(objFolder.Items, i) Next For Each strFileName in objFolder.Items     For i = 0 to 34         Wscript.Echo i & vbtab & arrHeaders(i) _             & ": " & objFolder.GetDetailsOf(strFileName, i)     Next Next

send us your feedback Send us your feedback « Previous | Next »   


Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 635

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net