Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 189
  • Last Modified:

How to know if a file exists

Has anyone got code to find out if a file exists before I use it in my app.
C
0
cuntacinte
Asked:
cuntacinte
  • 2
1 Solution
 
vinnyd79Commented:
If Dir("C:\Filename.txt") <> "" Then
0
 
vinnyd79Commented:
sorry about the above,this is what I meant

if Dir("C:\Filename.txt") <> "" Then
   MsgBox "File Exists!"
end if
0
 
cuntacinteAuthor Commented:
Thanks vinnyd79

C
0
 
RichWCommented:
Function FileExist(Fname As String) As Boolean
    On Local Error Resume Next
   FileExist = (Dir(Fname) <> "")
End Function

' Use
If FileExist("C:\MyFile.txt" Then
   Debug.Print "File Found"
End If

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now