Emily once commented with a nifty procedure for enumerating mapped drives. It uses the Windows Script Host Object Model. I created a function to convert mapped drives to UNC paths for an application I’m working on.
Dim wsNet As WshNetwork
Dim wsDrives As WshCollection
Dim i As Long
Dim sReturn As String
Set wsNet = New WshNetwork
Set wsDrives = wsNet.EnumNetworkDrives
sReturn = sPath
For i = 0 To wsDrives.Count – 1
If Left$(sPath, 2) = wsDrives.Item(i) Then
sReturn = Replace(sPath, wsDrives.Item(i), wsDrives.Item(i + 1), 1, 1)
ConvertMapped = sReturn
But I still have a problem. I have a list of documents and a list of links. The user can add a link by navigating to the document (using GetOpenFileName). If the document already exists in the Document table, the link is created. If not, a record is added to the Document table, then the link is created. I need to ensure there are no duplicates in the Document table.
I thought that converting paths to UNC paths would do it, but not so. The user can navigate to a document through multiple network shares. For instance, he could go to
\ActserverAIMUSAMydoc.pdf or he could go to
\ActserverAllCompaniesAIMUSAMydoc.pdf and he would be pointing to the same document. The paths don’t match, though, so this document could be added twice.
There’s only currently a few of these overlapping shares, so I could catch them “manually” in the code. That doesn’t seem like a good long term solution, though, as certainly another share will crop up that breaks it. Ideas?