-
I need to check to see if a file exists.
I'm not home right now, and wanted to check the theory I have......
If I try to OPEN a file for input (txt based), and put in a on-error goto line will this work? I'm not for sure how to write this out exactly though.
Like:
--------
On Error Goto Error1
Open "C:\test.txt" For Input As #1
Close #1
Exit Sub 'found the file - it exists
Error1:
Open "C:\test.txt" For Output As #1
Close #1 'Make the file
-------------
Did I get the theory right, and (if so) is there an easier (better) way to do this?
thanks!
-
<?>
Not quite
Code:
Private Command1_Click()
On Error Goto Error1: 'this will sent it to Error1
Open "C:\test.txt" For Input As #1
'do whatever
Close #1
'in error one we already have the error so we muct
'react to what the error will be
'file not found is 53
Error1:
If err.Number = 53 then
Msgbox "Sorry, file not fount!"
End IF
End Sub
-
<?>
I forgot:
If you want to check for the file's existance
If Dir("C:\test.txt") <> "" then MsgBox "File Exists"