Solved

How to check if a file exists?

Posted on 2002-05-30
2
168 Views
Last Modified: 2010-05-02
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
Comment
Question by:robertut
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 22

Expert Comment

by:rspahitz
ID: 7045447
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
 
LVL 22

Accepted Solution

by:
rspahitz earned 50 total points
ID: 7045449
Example:

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

Featured Post

Technology Partners: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month11 days, 7 hours left to enroll

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question