check file exists

I

iccsi

I would like to kown can I check file exists on a folder or not?
For example: if FileExists("C:'MyFile.txt)


Your information is great appreciated,
 
D

Dirk Goldgar

iccsi said:
I would like to kown can I check file exists on a folder or not?
For example: if FileExists("C:'MyFile.txt)


Your information is great appreciated,


Simple version:

If Len(Dir("C:\SomeFolder\MyFile.txt")) > 0 Then
' The file exists
Else
' It doesn't.
End If
 
O

omsoft

Try this.

Dim db As Database
Dim filepath As String
Dim fs
Dim strFullPath As String
Set db = CurrentDb
strFullPath = db.Name
filepath = Left$(strFullPath, InStrRev(strFullPath, "\"))
if fs.filexists(filepath & "file name") then
your code here.
endif
 
D

Dirk Goldgar

omsoft said:
Try this.

Dim db As Database
Dim filepath As String
Dim fs
Dim strFullPath As String
Set db = CurrentDb
strFullPath = db.Name
filepath = Left$(strFullPath, InStrRev(strFullPath, "\"))
if fs.filexists(filepath & "file name") then
your code here.
endif


That won't work as written. You'd need at least to create a
FileSystemObject and set the fs variable to point to it. But for most
purposes, I think FSO is overkill when all you want to do is find out if a
file exists.
 

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

Top