Results 1 to 3 of 3

Thread: Check to see if file exists

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2002
    Location
    Leeds, UK
    Posts
    75

    Check to see if file exists

    I want to run a check to see if a text file exists on my c:\drive.

    If i need to declare the function please include this in help.

    Thanks

  2. #2
    Addicted Member
    Join Date
    Aug 2002
    Location
    Coventry, England
    Posts
    169
    VB Code:
    1. Public Function FileExists(File As String) As Boolean
    2. Dim fLen As Integer
    3.    
    4.     On Error Resume Next
    5.     fLen = Len(Dir$(File))
    6.     If Err Or fLen = 0 Then
    7.         FileExists = False
    8.     Else
    9.         FileExists = True
    10.     End If
    11.  
    12. End Function
    13.  
    14.  
    15. ' Usage:
    16. If FileExists(App.Path & "\file.txt") Then
    17.     ' Do whatever here
    18. End If

  3. #3
    Lively Member
    Join Date
    Oct 2001
    Location
    Florida
    Posts
    98
    won't the dir command work also?

    The above method is probably a bit more solid, but also much larger.

    VB Code:
    1. if dir("C:\text.txt") = "" then do something

    = "" means it doesn't exist otherwise it does.

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