Vérifier la validé et l'existance d'un chemin de dossier, local ou distant

Contenu du snippet

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")


Compatibilité : VB6, VBA

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.