Does file exist

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

Thanks for the reply, I have been trying that, but I keep getting the same
results. The result I get is that the file exits, when it really doesn't.
All my msgbox display twice and I'm not sure why. Here is the code I'm
using. Can you help?

Public Const fnet As String = "\\server1\images"
Public pfile As String = "TEST01.TXT"
Private Sub DoesExist()

If System.IO.File.Exists(fnet & "\" & pfile) Then

MessageBox.Show(fnet & "\" & pfile & " file does not exist")
Else
MessageBox.Show(fnet & "\" & pfile & " file does exist")
End If

End Sub
 
Mike,

You have got your messages mixed up. It should be:

If System.IO.File.Exists(fnet & "\" & pfile) Then

MessageBox.Show(fnet & "\" & pfile & " file DOES exist")
Else
MessageBox.Show(fnet & "\" & pfile & " file does NOT exist")
End If

Kerry Moorman
 
Bear in mind that if File.Exists returns false it doesn't necessarily mean
that the file does not exist; it could mean that the caller has insufficient
permissions to actually test for the existence of the file. If File.Exists
is being used to determine whether or not a file needs to be created, it's
possible for the file creation to fail.
 
Hello, Mike,

Is it possible that you're just suffering a proofreading lapse? It
looks to me like the code you posted will report the message opposite to
the one you would normally want.

Cheers,
Randy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top