O'Reilly logo

VBScript in a Nutshell, 2nd Edition by Ron Petrusha, Matt Childs, Paul Lomax

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.”

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required