I’m working on this incomplete Function using the FSO to get a drive UNC. (Probably reinventing the wheel; the unwritten part of the function wil replace the drive letter with the UNC if applicable.) What I don’t understand is why I first have to set the Drives Collection, how come I can’t go straight to the Drive Item?
Function FileUNC(strPath as String) as String
Dim fso As FileSystemObject
Dim collDrives As Drives
Dim objDrive As Drive
Set fso = CreateObject(“Scripting.FileSystemObject”)
If fso.FileExists(strPath) Then
strFilePath = Left(fso.GetAbsolutePathName(strPath), 1)
Set collDrives = fso.Drives ‘ if I set the collection here the code works, but …
‘ How come neither of the next lines is valid as an alternative?
‘ Set objDrive = fso.Drives(strPath)
‘ Set objDrive = fso.Drives.Item(strPath)
‘ which would simplify this part to “With objDrive” …
With collDrives(strPath)
If .DriveType = 3 Then FileUNC = .ShareName
End With
Debug.Print FileUNC
End If
Set objDrive = Nothing
Set collDrives = Nothing
Set fso = Nothing
End Sub