Name
FileSystemObject.FolderExists Method
Syntax
oFileSysObj.FolderExists(FolderSpec)
oFileSysObjUse: Required
Data Type: FileSystemObject object
A FileSystemObject object.
FolderSpecUse: 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
FolderSpeccan’t contain wildcard characters.FolderSpeccannot include a filename as well as a path. In other words, the entireFolderSpecstring can only include drive and path information.If
FolderSpecdoes not include a drive specification, the current drive is assumed.FolderSpecis 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,
FolderSpeccan be a network path or share name. For example:If FileSys.FolderExists("\\NTSERV1\d$\TestPath\") ThenAmong 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") ...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