Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 155
  • Last Modified:

How to find if a File Exists?

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
mlcktmguy
Asked:
mlcktmguy
  • 3
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Private Sub Command1_Click()
    Dim fileName As String
   
    fileName = "c:\temp.txt"
    If Dir(fileName) <> "" Then
        Kill fileName
    End If
End Sub
0
 
flavoCommented:
myFile = "c:\myFile.txt"

If len(dir(myFile) then
  kill myFile
end if
0
 
flavoCommented:
hmm.. should have refreshed, got distracted.

Dave
0
 
flavoCommented:
>> If len(dir(myFile) then

If len(dir(myFile)) then
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now