Name
FileSystemObject.GetFile Method
Syntax
oFileSysObj.GetFile(FilePath)
oFileSysObjUse: Required
Data Type: FileSystemObject object
A FileSystemObject object.
FilePathUse: Required
Data Type: String
A path and filename.
Return Value
File object.
Description
Returns a reference to a File object.
Rules at a Glance
FilePathcan be an absolute or a relative path.If
FilePathis 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
FilePathcan’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 copying 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 can also save yourself a step by calling the FileSystemObject object’s OpenTextFile method.
You should first use GetAbsolutePathName to create the required
FilePathstring.If
FilePathincludes a network drive or share, you could use the DriveExists method to confirm that the required drive is available prior to calling the GetFile method.Since GetFile generates an error if the file designated in
FilePathdoesn’t exist, you should call the FileExists method before calling GetFile.You must use the
Setstatement to ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access