Visual Basic doesn't provide a function to verify if a file exists, but you can use the Dir$ function for this purpose. The following code shows how you can easily implement your own FileExists function. You must trap errors in the event that an invalid drive is specified.
Function bFileExists(sFileName As String) As Integer
Dim I As Integer
On Error Resume Next
I = Len(Dir$(sFileName))
If Err Or I = 0 Then
bFileExists = False
Else
bFileExists = True
End If
End Function
This tip is reprinted from the VB Tips &
|