FileSystemObject.GetFile Method (VB6)

Syntax

oFileSysObj.GetFile(FilePath)

oFileSysObj

Use: Required

Data Type: FileSystemObject object

Any object variable returning a FileSystemObject object.

FilePath

Use: Required

Data Type: String

A path and filename.

Return Value

File object.

Description

Returns a reference to a File object.

Rules at a Glance

  • FilePath can be an absolute or a relative path.

  • If FilePath is a share name or network path, GetFile ensures that the drive or share exists as part of the process of creating the File object.

  • If any part of the path in FilePath can't be contacted or doesn't exist, an error occurs.

Programming Tips and Gotchas

  • The object returned by GetFile is a File object, not a TextStream object. A File object isn't an open file; the point of the File object is to perform methods such as coping or moving files and interrogating a file's properties. Although you can't write to or read from a File object, you can use the File object's OpenAsTextStream method to obtain a TextStream object.

  • You should first use GetAbsolutePathName to create the required FilePath string.

  • If FilePath includes a network drive or share, you could use the DriveExists method to confirm the required drive is available prior to calling the GetFile method.

  • Since GetFile generates an error if the file designated in FilePath doesn't exist, you should call the FileExists method before calling GetFile.

  • You must use the Set statement to assign the File object reference to a local object ...

Get VB & VBA in a Nutshell: The Language now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.