How to check if a file exists?

I want to perform a Kill Statement on a file(to delete it if a certain event occures) but I need to know before if the file exists(to avoid the error).
I tried the On Error but it doesn't work.
Any ideas?
Thank you
robertutAsked:
Who is Participating?
 
rspahitzConnect With a Mentor Commented:
Example:

strFilename = "C:\Temp\myfile.txt"
if Dir$(strFilename) <> vbNullString then
  kill strFilename
end if
0
 
rspahitzCommented:
Using the same path that would appear in the kill, just use Dir$(filename).  If it returns vbnullstring ("") then the file does not exist.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.