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:
If the file has special attributes (eg: is Hidden) you need to specify this too, eg:VB Code:
If Dir("C:\Test.txt") <> "" Then Msgbox "File exists" Else Msgbox "File does not exist" End If
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).
Just call the above function with the path of the file to check as its parameter.VB Code:
Private Function CheckPath(strPath As String) As Boolean If Dir$(strPath) <> "" Then CheckPath = True Else CheckPath = False End If End Function
Cheers,
RyanJ




Reply With Quote