GetBaseName Method
Returns a string containing the base name of the last component, less any file extension, in a path.
Syntax
object.GetBaseName(path)
Arguments:
- Object: Required. Always the name of a
FileSystemObject
. - Path: Required. The path specification for the component whose base name is to be returned.
Remarks
The GetBaseName
method returns a zero-length string (" ") if no
component matches the path argument.
Note:
The GetBaseName
method works only on the provided path string
with file extension. It does not attempt to resolve the path, nor does it check
for the existence of the specified path.
The following example illustrates the use of the GetBaseName
method.
Example 1:
Function GetTheBase(filespec)
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
GetTheBase = fso.GetBaseName(filespec)
End Function
' Usage
Dim baseName
baseName = GetTheBase("C:\testfile.txt")
' Output: testfile
Example 2:
Function GetTheBase(filespec)
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
GetTheBase = fso.GetBaseName(filespec)
End Function
' Usage
Dim emptyPath
emptyPath = GetTheBase("")
' Output: ""