Name

FileSystemObject.GetParentFolderName Method

Syntax

                  oFileSysObj.GetParentFolderName(Path)
oFileSysObj

Use: Required

Data Subtype: FileSystemObject object

Any object variable returning a FileSystemObject object.

Path

Use: Required

Data Subtype: String

A path specifier.

Return Value

A Variant of subtype String.

Description

Returns the folder name immediately preceding the last element of a given path. In other words, if Path ends in a filename, the method returns the path to the folder containing that file. If Path ends in a folder name, the method returns the path to that folder’s parent.

Rules at a Glance

  • If the parent folder name can’t be determined from Path, a zero-length string (“”) is returned.

  • Path can be a relative or absolute reference.

Programming Tips & Gotchas

  • GetParentFolderName doesn’t verify that any element of Path exists.

  • Path can be a network drive or share.

  • GetParentFolderName assumes that the last element of the string that isn’t part of a drive specifier is the parent folder. It makes no other check than this. As with all the Getx Name methods of the FileSystemObject object, the GetParentFolderName method is more a string parsing and manipulation routine than an object-related routine.

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.