Results 1 to 5 of 5

Thread: See if File exists

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2000
    Location
    California
    Posts
    154
    How do you check to see if a file exists?

  2. #2
    Guest
    Use the Dir function.

    Code:
    If Dir("C:\file.exe") <> "" Then
    'file exists
    Else
    'file does not exist
    End If

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 2000
    Location
    California
    Posts
    154
    Thanks

  4. #4
    Junior Member
    Join Date
    Aug 2000
    Location
    Rockford, IL
    Posts
    21

    or you can use this...

    Function FileExists(strPath As String) As Boolean
    Dim lngRetVal As Long
    On Error Resume Next
    lngRetVal = Len(Dir$(strPath))
    If Err Or lngRetVal = 0 Then
    FileExists = False
    Else
    FileExists = True
    End If
    End Function



    This way you can do something like this.

    If FileExists("C:\temp\seenit.txt") = True Then
    MsgBox "They Seen it!"
    else
    MsgBox "Didn't see it!"
    End If



  5. #5
    Guest
    Or use the FileSystemObject.
    Code:
    Dim X As FileSystemObject
    If X.FileExists("MyFile.txt") Then 'File does exist

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