Name
FileSystemObject.GetFileName Method
Syntax
oFileSysObj.GetFileName(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 filename element of a given path.
Rules at a Glance
If the filename can’t be determined from the given
Path, a zero-length string (” “) is returned.Pathcan be a relative or absolute reference.
Programming Tips and Gotchas
GetFileName doesn’t verify that a given file exists in
Path.Pathcan be a network drive or share.Like all the Getx Name methods of the FileSystemObject object, the GetFileName method is more a string manipulation routine that an object-related routine. GetFileName has no built-in intelligence (and, in fact, seems to have even less intelligence than usual for this set of methods); it simply assumes that the last element of the string that is not part of a drive and path specifier is in fact a filename. For example, if
Pathis C:\Windows, the method returns the string “Windows”; if Path is C:\Windows\ (which unambiguously denotes a folder rather than a filename), the method still returns the string “Windows.”
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