Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to verify the file is there? 1

Status
Not open for further replies.

EwS

Programmer
Dec 30, 2002
398
US
I need to make sure that a specific file exists in a specific directory. What function do I use? (I can't find it in MSDN).

Thank you.
 
The DIR function should provide some help

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 

Here's another alternative.
If it can't open the file presumably the file doesn't exist.
There may be an obscure time when it doesn't work.
So far I haven't seen it fail yet.
Code:
Public Function FileExists(Filename as string) as Boolean
  On Local Error got FileOpenError
  Dim FileNum as long
  FileNum = Freefile
  OPEN Filename FOR INPUT AS FileNum
  Close FileNum
  FileExists = True
Exit Function

:FileOpenError
 FileExists = False
End Function

________________________________________________________________________________
You can't put a square peg in a round hole without a lot of force.
If at first you don't succeed get a bigger hammer. - Steve 2003.
 
I use something like this:

If Dir("File.xls") > "" Then
Set FileObj = GetObject("File.xls")
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top