Visual basic has a built-in function called Dir which lists files for you, based on options you specify.
If you specify a full filename (and path) it will return the filename if the file exists. If the specified file doesn't
exist, an empty string "" will be returned.
To find the file C:\Test.txt you would do the following:
VB Code:
If Dir("C:\Test.txt") <> "" Then
Msgbox "File exists"
Else
Msgbox "File does not exist"
End If
If the file has special attributes (eg: is Hidden) you need to specify this too, eg:
VB Code:
If Dir("C:\Test.txt", vbHidden) <> "" Then
Msgbox "File exists"
End If
Here is a function you can use which returns True if the specified file exists (or False if it doesn't).
VB Code:
Private Function CheckPath(strPath As String) As Boolean
If Dir$(strPath) <> "" Then
CheckPath = True
Else
CheckPath = False
End If
End Function
Just call the above function with the path of the file to check as its parameter.
Cheers,
RyanJ