FileSystemObject.GetFile Method (VB6) |
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.
File object.
Returns a reference to a File object.
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.
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 variable.