Name
FileSystemObject.GetFileName Method
Syntax
oFileSysObj
.GetFileName(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 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.Path
can be a relative or absolute reference.
Programming Tips & Gotchas
GetFileName doesn’t verify that a given file exists in
Path
.Path
can 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
Path
isC:\Windows
, the method returns the string “Windows”; if Path isC:\Windows\
(which unambiguously denotes a folder rather than a filename), the method still returns the string “Windows.”
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.