check for a file

  • Thread starter Thread starter Keith
  • Start date Start date
K

Keith

I have a routine that uses the kill command to remove old versions of a
file before it creates a new version.

However if the routine is being run for the first time and the files it
has been asked to kill don't currently exist, I get an error message and
the rest of the script doesn't run.

How can I check to see if the files exist before running the kill command?

Anybody know?

Regards

Keith
 
Dir() should do the job.
Returns a zero-length string if there is no file.
 
You can use Dir to check before killing as Allen advised.

Another way is to use "Om Error Resume Next" before Kill (and switch back to
normal error-trapping after Kill). This way, when Kill errors out, VBA will
just clear the error and resume with the next statement.
 
Thanks,

The on error would work best since the directory I am checking has lots
of other files in it, and is never empty.

Thanks

Keith
 

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

Back
Top