Name

FileSystemObject.GetFolder Method

Syntax

                  oFileSysObj
                  .GetFolder(FolderPath)
oFileSysObj

Use: Required

Data Type: FileSystemObject object

A FileSystemObject object.

FolderPath

Use: Required

Data Type: String

A path to the required folder.

Return Value

A Folder object.

Description

Returns a reference to a Folder object.

Rules at a Glance

  • FolderPath can be an absolute or relative path.

  • If FolderPath is a share name or network path, GetFolder ensures that the drive or share exists as part of the process of returning the Folder object.

  • If any part of FolderPath doesn’t exist, an error occurs.

Programming Tips and Gotchas

  • You should first use GetAbsolutePathName to create the required FolderPath string.

  • If FolderPath includes a network drive or share, you could use the DriveExists method to confirm the required drive is available prior to calling the GetFolder method.

  • Since GetFolder requires that FolderPath is the path to a valid folder, you should call the FolderExists method to verify that FolderPath exists.

  • The GetFolder method allows you to directly obtain an object reference to a particular folder. You can also use the Item property of the Folders collection object for cases in which you must navigate the filesystem to reach a particular folder, or for those cases in which you’re interested in enumerating the subfolders belonging to a particular folder.

  • You must use the Set statement to assign the Folder object reference to a local object variable.

Get VBScript in a Nutshell, 2nd Edition 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.