check file exists

  • Thread starter Thread starter iccsi
  • Start date Start date
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,
 
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
 
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
 
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.
 
Back
Top