Solved

How to find if a File Exists?

Posted on 2004-08-15
4
144 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
DO Loop not working 4 72
message box in access 4 41
VB6 - Compare and highlight cell not the same 3 42
Problem to With line 4 36
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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

939 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now