傳回包含路徑中最後一個元件之基礎名稱 (不含任何副檔名) 的字串。
語法
object.GetBaseName(path)
引數:
FileSystemObject 的名稱。備註
如果沒有符合路徑引數的元件,則 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: ""