VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



A Beginner method to check whether a file exists

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.

Rate A Beginner method to check whether a file exists

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

Download this snippet    Add to My Saved Code

A Beginner method to check whether a file exists Comments

No comments have been posted about A Beginner method to check whether a file exists. Why not be the first to post a comment about A Beginner method to check whether a file exists.

Post your comment

Subject:
Message:
0/1000 characters