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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determining if a file exists

Status
Not open for further replies.

CaKiwi

Programmer
Apr 8, 2001
1,294
US

What is the best way to determine if a file exists? My current method is to try opening it or to call FileDateTime to see if I get an error but I thought there might be a more elegant way.

CaKiwi

"I love mankind, it's people I can't stand" - Linus Van Pelt
 
Hi,

You can use the Dir() function as in

If Dir(path & filename) <> &quot;&quot; then
code
End if

Mark

The key to immortality is to make a big impression in this life!!
 

Thanks, that should work. I'll try it tonight.

CaKiwi

&quot;I love mankind, it's people I can't stand&quot; - Linus Van Pelt
 
You might consider using the FileSystemObject, which has a FileExists method you can interrogate:

object.FileExists(filespec)

The FileExists method syntax has these parts:

Part Description
object Required. Always the name of a FileSystemObject.
filespec Required. The name of the file whose existence is to be determined. A complete path specification (either absolute or relative) must be provided if the file isn't expected to exist in the current folder.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top