Consider the following VBScript which, when run, lists all the files in the current directory and their properties:
Option Explicit
Dim oShell : Set oShell = CreateObject("Shell.Application")
Dim oFSO : Set oFSO = CreateObject("Scripting.FileSystemObject")
Dim oFolder : Set oFolder = oShell.Namespace(oFSO.GetParentFolderName(Wscript.ScriptFullName))
Dim oFile, iPos, sHeader(999), sVal
' Get a list of the property names
For iPos = 0 to 999
sHeader(iPos) = oFolder.GetDetailsOf(oFolder.Items, iPos)
Next
' For each file in this folder, print the property name and the value
For Each oFile in oFolder.Items
WScript.Echo "Looking at " & oFile.Name
For iPos = 0 To 999
sVal = oFolder.GetDetailsOf(oFolder.ParseName(oFile.Name), iPos)
If sVal <> "" Then WScript.Echo sHeader(iPos) & " (" & iPos & "): " & sVal
Next
Next
If I run this in a folder that contains only this file and with the Windows setting “Hide extensions for known file types” disabled, then I get the following (correct) output:
D:\defect>cscript //NOLOGO list_metadata.vbs Looking at list_metadata.vbs Name (0): list_metadata.vbs Size (1): 740 bytes Item type (2): VBScript Script File Date modified (3): 19/02/2012 12:26 Date created (4): 23/02/2012 22:16 Date accessed (5): 23/02/2012 22:16 Attributes (6): A Perceived type (9): Unspecified Owner (10): HOME\Richard Kind (11): Program Rating (19): Unrated Computer (53): HOME (this computer) Filename (155): list_metadata.vbs Shared (173): No Folder name (176): defect Folder path (177): D:\defect Folder (178): defect (D:) Path (180): D:\defect\list_metadata.vbs Type (182): VBScript Script File Link status (188): Unresolved Sharing status (269): Not shared
However if I run this again with “Hide extensions for known file types” enabled, then the value for each item is exactly the same as the property and the name of the file in the first line is missing the extension:
D:\defect>cscript //NOLOGO list_metadata.vbs Looking at list_metadata Name (0): Name Size (1): Size Item type (2): Item type Date modified (3): Date modified ...lots deleted... Frame width (285): Frame width Total bitrate (286): Total bitrate Masters Keywords (debug) (287): Masters Keywords (debug) Masters Keywords (debug) (288): Masters Keywords (debug)
Does anyone know how I can modify this code so that it will work irrespective of whether or not this setting is applied in Windows?
The
Nameproperty is the display name, not the file name. For the file name, use thePathproperty. But why are you extracting the name from the item, and then parsing the name back into an item? Why not just use the item directly?