Does a file exist

dbalargin

Member
Local time
Today, 13:38
Joined
Dec 31, 2002
Messages
39
I am attempting to kill a file. I first need to know if this file exists. If it doesn't, I get an error that says file not found. What can I do to see if the file exists before I try to kill it?
 
Have you considered putting an

On Error Resume Next

statement just before the statement that deletes the file?
 
Yes,
But I want to know how to prevent it instead of just turning my head and looking the other way.
 
OK. You can use something like this:

Dim intFileCount as integer, fs
Set fs = Application.FileSearch
With fs
.LookIn = "C:\yourdirectorypath"
.FileName = "yourfilename"
intFileCount = .Execute
End With


If intFilecount is greater than 0 then the file exists.
 

Users who are viewing this thread

Back
Top Bottom