I don't know how to get the name of a folder in a UNC path with the FileSystemObject object. For example:
From "\\Server\FolderA" I would like to be able to get "FolderA". The method I was hoping would work is "GetBaseName" but it doesn't seem to work when the "IsRootFolder" property is True.
The following procedure:
Public Sub GetUNCFolderName()
Const stPathA As String = "\\Server\FolderA"
Const stPathB As String = "\\Server\FolderA\FolderB"
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Debug.Print "---------"
Debug.Print "Path A: " & stPathA
Debug.Print "GetAbsolutePathName: " & fso.GetAbsolutePathName(stPathA)
Debug.Print "GetBaseName : " & fso.GetBaseName(stPathA)
Debug.Print "IsRootFolder : " & fso.GetFolder(stPathA).IsRootFolder
Debug.Print "---------"
Debug.Print "Path B: " & stPathB
Debug.Print "GetAbsolutePathName: " & fso.GetAbsolutePathName(stPathB)
Debug.Print "GetBaseName : " & fso.GetBaseName(stPathB)
Debug.Print "IsRootFolder : " & fso.GetFolder(stPathB).IsRootFolder
End Sub
Returns this result:
---------
Path A: \\Server\FolderA
GetAbsolutePathName: \\Server\FolderA
GetBaseName :
IsRootFolder : True
---------
Path B: \\Server\FolderA\FolderB
GetAbsolutePathName: \\Server\FolderA\FolderB
GetBaseName : FolderB
IsRootFolder : False
As you can see "fso.GetBaseName(stPathA)" returns an empty string and "fso.GetBaseName(stPathB)" does not.
I appreciate any ideas you can give me.