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.FolderExists Method

Syntax

                  oFileSysObj
                  .FolderExists(FolderSpec)
oFileSysObj

Use: Required

Data Type: FileSystemObject object

A FileSystemObject object.

FolderSpec

Use: Required

Data Type: String

The complete path to the folder.

Return Value

Boolean (True or False).

Description

Determines whether a given folder exists; the method returns True if the Folder exists, and returns False if not.

Rules at a Glance

  • FolderSpec can’t contain wildcard characters.

  • FolderSpec cannot include a filename as well as a path. In other words, the entire FolderSpec string can only include drive and path information.

  • If FolderSpec does not include a drive specification, the current drive is assumed.

  • FolderSpec is interpreted as an absolute path if it begins with a drive name and a path separator, and it is interpreted as an absolute path on the current drive if it begins with a path separator. Otherwise, it is interpreted as a relative path.

Programming Tips and Gotchas

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

    If FileSys.FolderExists("\\NTSERV1\d$\TestPath\") Then
  • Among its string manipulation methods, the Scripting Runtime library lacks one that will extract a complete path from a path and filename. The example provides the GetCompletePath function to perform this useful task, as well as to illustrate the use of the FolderExists method.

Example

Function GetCompletePath(sPath) Dim oFS Dim sFileName, sPathName Dim lPos Set oFS = CreateObject("Scripting.FileSystemObject") ...

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