Name
FileSystemObject.FileExists Method
Syntax
oFileSysObj.FileExists(FileSpec)
oFileSysObjUse: Required
Data Type: FileSystemObject object
A FileSystemObject object.
FileSpecUse: Required
Data Type: String
A complete path to the file.
Return Value
Boolean (True or False).
Description
Determines if a given file exists.
Rules at a Glance
Returns
Trueif the file exists or is connected to the machine, and returnsFalseif not.FileSpeccan’t contain wildcard characters.FileSpeccan include either an absolute or a relative path—that is, a path that is relative to the current folder. The current folder is the folder in which the script is running, or the folder specified in the “Start in” text box of the shortcut used to launch the script. The symbol to indicate the parent of the current folder is (..); the symbol to indicate the current folder is (.). IfFileSpecdoes not include a path, the current folder is used.
Programming Tips and Gotchas
If the user has adequate rights,
FileSpec can be a network path or share
name. For example:
If ofs.FileExists("\\TestPath\Test.txt") ThenBecome 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