Does File Exist Test?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can you verify that a file exists? Is there a function that you can feed
the path and file name as arguments and it will tell you if the file exists
(that is, the path and file name are accurate?

Thank you.

Ross
 
Yes....oddly enough it is called FileExists, but it requires that you
instantiate the FileSystemObject, i.e.,

Dim fso as variant
Dim blnResult as Boolean

Set fso = CreateObject("Scripting.FileSystemObject")

blnResult = fso.FileExists("file spec here")

Another (simpler) way would be to use the Dir function, i.e.,

Dim blnResult As Boolean

blnResult = Len(Dir("file spec here"))>0
 
Thank you Paul!

Ross

Paul Overway said:
Yes....oddly enough it is called FileExists, but it requires that you
instantiate the FileSystemObject, i.e.,

Dim fso as variant
Dim blnResult as Boolean

Set fso = CreateObject("Scripting.FileSystemObject")

blnResult = fso.FileExists("file spec here")

Another (simpler) way would be to use the Dir function, i.e.,

Dim blnResult As Boolean

blnResult = Len(Dir("file spec here"))>0
 
Yes, I don't remember the exact syntax. But you're looking to use the
FileSystemObject and its various methods.
 
Or the Dir function, which means you don't have the overhead of
instantiating FSO.
 
How can you verify that a file exists?

As Doug says:

If Len(Dir(strMyFilePath)) = 0 Then
' it's not there

Else
' it's there

End If


HTH

Tim F
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top