Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 173
  • Last Modified:

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
0
robertut
Asked:
robertut
  • 2
1 Solution
 
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
 
rspahitzCommented:
Example:

strFilename = "C:\Temp\myfile.txt"
if Dir$(strFilename) <> vbNullString then
  kill strFilename
end if
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now