Name
FileSystemObject.GetFileName Method
Syntax
oFileSysObj
.GetFileName(Path
)
oFileSysObj
Use: Required
Data Type: FileSystemObject object
A FileSystemObject object.
Path
Use: 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.Path
can be a relative or absolute reference.
Programming Tips and 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
is 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.”
Get VBScript in a Nutshell, 2nd Edition 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.