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
Solved

How to find if a File Exists?

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA Word macro - how to get characters after the searched for string 5 94
bit defender blocks good applications 2 101
Run code from text file in vb 1 73
TT Auto Dashboard 13 95
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…
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.
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…

829 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