O'Reilly logo

VBScript in a Nutshell, 2nd Edition by Ron Petrusha, Matt Childs, Paul Lomax

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

FileSystemObject.FileExists Method

Syntax

                  oFileSysObj.FileExists(FileSpec)
oFileSysObj

Use: Required

Data Type: FileSystemObject object

A FileSystemObject object.

FileSpec

Use: 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 True if the file exists or is connected to the machine, and returns 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 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") Then

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required