Name
FileSystemObject.FolderExists Method
Syntax
oFileSysObj
.FolderExists(FolderSpec
)
-
oFileSysObj
Use: Required
Data Subtype: FileSystemObject object
Any object variable returning a FileSystemObject object.
-
FolderSpec
Use: Required
Data Subtype: 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,
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 entireFolderSpec
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 & Gotchas
If the user has adequate rights,
FolderSpec
can be a network path or share name. For example:If ofs.FileExists("\\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 ...
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.