Does file exist

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike

    #1

    Does file exist

    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\imag es"
    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



  • Kerry Moorman

    #2
    RE: Does file exist

    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

    "Mike" wrote:
    [color=blue]
    > 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\imag es"
    > 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
    >
    >
    >
    >[/color]

    Comment

    • Kevin Westhead

      #3
      Re: Does file exist

      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.

      --
      Kevin Westhead

      "Kerry Moorman" <KerryMoorman@d iscussions.micr osoft.com> wrote in message
      news:4380C96E-448E-43C3-9AFC-7E465AC0092F@mi crosoft.com...[color=blue]
      > 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[/color]


      Comment

      • R. MacDonald

        #4
        Re: Does file exist

        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


        Mike wrote:[color=blue]
        > 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\imag es"
        > 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
        >
        >
        >[/color]

        Comment

        Working...