Hi I have a form where a user can enter a path name into a text box and I want to be able to check if the path name is valid. By valid I mean contains the right syntax. Is there a way to accomplish this in vb6.

Thanks in advance,

Try this :

Function FileExists(FileName As String) As Boolean
On Error GoTo ErrorHandler
' get the attributes and ensure that it isn't a directory
FileExists = (GetAttr(FileName) And vbDirectory) = 0
ErrorHandler:
' if an error occurs, this function returns False
End Function

example to call :

Private Sub btnCheck_Click()
    If FileExists(txtPath.Text) = True Then
        MsgBox "File found"
    ElseIf FileExists(txtPath.Text) = False Then
        MsgBox "File Not Found"
    End If
End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.