Name

FileSystemObject.FileExists Method

Syntax

                  oFileSysObj.FileExists(FileSpec)
oFileSysObj

Use: Required

Data Subtype: FileSystemObject object

Any object variable returning a FileSystemObject object.

FileSpec

Use: Required

Data Subtype: 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 True if the file exists or is connected to the machine, False if not.

  • FileSpec can’t contain wildcard characters.

  • FileSpec can 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 (.). If FileSpec does not include a path, the current folder is used.

Programming Tips & Gotchas

If the user has adequate rights, FileSpec can be a network path or share name. For example:

If ofs.FileExists("\\TestPath\Test.txt") Then

Get VBScript in a Nutshell 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.