Name
FileSystemObject.GetParentFolderName Method
Syntax
oFileSysObj.GetParentFolderName(Path)
oFileSysObjUse: Required
Data Type: FileSystemObject object
A FileSystemObject object.
PathUse: Required
Data Type: String
A path specifier.
Return Value
A 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.Pathcan be a relative or absolute reference.
Programming Tips and Gotchas
GetParentFolderName doesn’t verify that any element of
Pathexists.Pathcan 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.
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