OpenFile

Opens a file by path and returns a FileProperties collection of its Windows shell properties.

Syntax: object.OpenFile(FilePath [ , WriteSupport ])

object
required An object expression that evaluates to a FilePropertyExplorer object. The predeclared default instance is available as FilePropertyExplorer.
FilePath
required A String giving the path to a valid file.
WriteSupport
optional A Boolean that controls whether the returned FileProperties collection is opened with write support for property values. False (default) opens it without write support. Pass True to allow setting FileProperty.Value.

OpenFile returns a FileProperties collection for the specified file. The collection contains the FileProperty entries for the properties the operating system exposes for that file. Common examples include the duration of an audio file such as an MP3 and the EXIF properties of a JPEG image.

OpenFile raises run-time error -2147212790 (File not found or is not accessible) when the file does not exist. It never returns Nothing.

Write support requires Windows Vista or newer.

Note 1.7.1.0

FilePath must be a full path that uses backslashes, such as C:\Folder\File.ext. A path that is relative, has a .. segment or uses forward slashes raises the same error as a missing file, although the file exists.

Note 1.7.1.0

For a file type that has a property handler of its own, such as JPEG, a collection opened with WriteSupport set to True holds only the properties of that handler. It has a lower Count than a collection of the same file opened without write support, and a property of the file system, such as System.Size, is in it with an empty Value. Read those properties from a collection opened without write support. A file type without a handler, such as a text file, lists the same properties either way.

Example

This example opens an MP3 file and prints all its shell properties to the Debug console.

Dim Props As FileProperties
Set Props = FilePropertyExplorer.OpenFile("C:\Music\track.mp3")

Debug.Print "File: " & Props.FilePath
Debug.Print "Properties: " & Props.Count

Dim i As Long
For i = 0 To Props.Count - 1
    Dim Prop As FileProperty
    Set Prop = Props.Item(i)
    Debug.Print Prop.NameDesc & " = " & Prop.ValueDesc
Next i

See Also