Results 1 to 3 of 3

Thread: How to check to see if I file exists (think I know...)?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Posts
    84
    I need to check to see if a file exists.

    I'm not home right now, and wanted to check the theory I have......

    If I try to OPEN a file for input (txt based), and put in a on-error goto line will this work? I'm not for sure how to write this out exactly though.

    Like:

    --------
    On Error Goto Error1
    Open "C:\test.txt" For Input As #1
    Close #1
    Exit Sub 'found the file - it exists

    Error1:
    Open "C:\test.txt" For Output As #1
    Close #1 'Make the file
    -------------


    Did I get the theory right, and (if so) is there an easier (better) way to do this?


    thanks!

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Not quite
    Code:
    Private Command1_Click()
      On Error Goto Error1: 'this will sent it to Error1
      Open "C:\test.txt" For Input As #1 
        'do whatever
      Close #1 
     
    'in error one we already have the error so we muct
    'react to what the error will be
    'file not found is 53
    
    Error1: 
      If err.Number = 53 then
        Msgbox "Sorry, file not fount!"
       End IF
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    I forgot:
    If you want to check for the file's existance

    If Dir("C:\test.txt") <> "" then MsgBox "File Exists"
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width