GetBaseName 方法

返回一个字符串,其中包含路径中最后一个组件的基本名称(不包括任何文件扩展名)。

语法

object.GetBaseName(path)

参数:

  • Object必需。始终为 FileSystemObject 的名称。
  • Path必需。指定要返回其基本名称的组件所在的路径。

注释

如果没有组件与 path 参数匹配,则 GetBaseName 方法返回零长度字符串 (" ")。

注:

GetBaseName 方法仅对提供的具有文件扩展名的路径字符串有效。它不会尝试解析路径,也不会检查指定的路径是否存在。

以下示例说明了 GetBaseName 方法的用法。

示例 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

示例 2

Function GetTheBase(filespec)
    Dim fso
    Set fso = CreateObject("Scripting.FileSystemObject")
    GetTheBase = fso.GetBaseName(filespec)
End Function

' Usage
Dim emptyPath
emptyPath = GetTheBase("")
 ' Output: ""