Private Declare Function PathGetDriveNumber Lib "shlwapi.dll" Alias "PathGetDriveNumberA" (ByVal pszPath As String) As Long
Private Declare Function PathIsDirectory Lib "shlwapi.dll" Alias "PathIsDirectoryA" (ByVal pszPath As String) As Long
Private Declare Function PathIsNetworkPath Lib "shlwapi.dll" Alias "PathIsNetworkPathA" (ByVal pszPath As String) As Long
Public Function IsValidFolderPath(ByVal sString As String) As Boolean
If LenB(sString) Then 'argument non vide
' ajoute dernier antislash
If Not RightB$(sString, 2) = "\" Then sString = sString & "\"
If PathGetDriveNumber(sString) = -1 Then
' chemin réseau?
IsValidFolderPath = PathIsNetworkPath(sString)
Else
' commence par une lettre drive, valide?
IsValidFolderPath = PathIsDirectory(sString)
End If
End If
End Function
' EXEMPLE
MsgBox IsValidFolderPath("C:\Temp\")
MsgBox IsValidFolderPath("V:")
MsgBox IsValidFolderPath("192.168.1.1")
MsgBox IsValidFolderPath("\\127.0.0.1")
MsgBox IsValidFolderPath("bonjour")