Solved

How to find if a File Exists?

Posted on 2004-08-15
4
146 Views
Last Modified: 2010-05-02
Very Simple.  I want to know if a particular file (temp.txt) exists before I try to kill it.  Sometimes it's there and sometimes it's not.  if it's not Kill \temp.txt fails.

I read in my book about the function FileExists(\temp) but my version of VB does not have it available.  Is there another way to do it?

0
Comment
Question by:mlcktmguy
  • 3
4 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 125 total points
ID: 11807280
Private Sub Command1_Click()
    Dim fileName As String
   
    fileName = "c:\temp.txt"
    If Dir(fileName) <> "" Then
        Kill fileName
    End If
End Sub
0
 
LVL 34

Expert Comment

by:flavo
ID: 11807289
myFile = "c:\myFile.txt"

If len(dir(myFile) then
  kill myFile
end if
0
 
LVL 34

Expert Comment

by:flavo
ID: 11807292
hmm.. should have refreshed, got distracted.

Dave
0
 
LVL 34

Expert Comment

by:flavo
ID: 11807294
>> If len(dir(myFile) then

If len(dir(myFile)) then
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

785 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