PDA

View Full Version : Solved: Code that returns the full path of a link



sassora
06-23-2012, 07:41 AM
Hi

Is there a way of taking a folder path:
G:\folder

and finding the full path, for example:
\\server\sup\folder


Thanks a lot

shrivallabha
06-23-2012, 11:21 AM
See this link:
http://www.dailydoseofexcel.com/archives/2007/04/25/converting-mapped-drives/
Let us know if it helps you.

sassora
06-23-2012, 03:15 PM
Thanks, this does work if the drive letter is upper case.

Can it be made case insensitive, I have tried including some Ucase() functions so far.

'Switch on Windows Script Host Object Model in the Visual Basic Editor references

Public Function ConvertMapped(ByVal sPath As String) As String

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)
Exit For
End If
Next i

ConvertMapped = sReturn

End Function

Kenneth Hobs
06-23-2012, 03:53 PM
If LCase(Left$(sPath, 2)) = LCase(wsDrives.Item(i)) Then

sassora
06-24-2012, 12:32 AM
Thanks, I've now tried that with LCase and UCase but

Z:\ returns the full path and

z:\ just returns "z:\"

sassora
06-24-2012, 01:39 AM
I've made sure that the path going in to the function is uppercase by making both instances of sPath uppercase.

'Switch on Windows Script Host Object Model in the Visual Basic Editor references

Public Function ConvertMapped(ByVal sPath As String) As String

Dim wsNet As WshNetwork
Dim wsDrives As WshCollection
Dim i As Long
Dim sReturn As String
Dim sUpperPath As String

Set wsNet = New WshNetwork
Set wsDrives = wsNet.EnumNetworkDrives

sUpperPath = UCase(sPath)
sReturn = sUpperPath

For i = 0 To wsDrives.Count - 1
If Left$(sUpperPath, 2) = wsDrives.Item(i) Then
sReturn = Replace(sUpperPath, wsDrives.Item(i), wsDrives.Item(i + 1), 1, 1)
Exit For
End If
Next i

ConvertMapped = sReturn

End Function

Thanks for help all.