by Jacky Wong (2 Submissions)
Category: Files/File Controls/Input/Output
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (7 Votes)
A Beginner method to check whether the file exists or not. It is simple, easy to understand and should able to run on different Window OS.
Public Function CheckFile(InFileName As String) As Boolean
On Error GoTo ErrHandler
CheckFile = False
'Check whether the file or folder exist
If Dir(InFileName) <> "" Then
'Check is it a directory(folder)
If (GetAttr(InFileName) And vbDirectory) = 0 Then
CheckFile = True
Else
MsgBox "File doesn't exist!", vbCritical
Exit Function
End If
Else
MsgBox "File doesn't exist!", vbCritical
Exit Function
End If
ErrHandler:
End Function