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.Pathcan be a relative or absolute reference.
Programming Tips & 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