Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
 
 
 
500MB 27GB Web Hosting - $9.95/Month
 
 
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
TitleSee if a file exists four ways
Keywordsfile, exists
CategoriesFiles & Directories
 
Use Dir$, Open, FileLen and GetAttr. Note that Open may cause trouble if the file is locked by another application.

Thanks to Tom Steemson

 
Private Function FileExistsWithDir(ByVal filename As String)
Dim file_name As String

    On Error Resume Next
    file_name = Dir$(filename)
    FileExistsWithDir = (file_name <> "")
End Function

Private Function FileExistsWithOpen(ByVal filename As _
    String)
Dim fnum As String

    fnum = FreeFile
    On Error GoTo FileDoesntExist
    Open filename For Input As fnum
    Close fnum
    FileExistsWithOpen = True
    Exit Function
    
FileDoesntExist:
    FileExistsWithOpen = False
End Function

Private Function FileExistsWithFileLen(ByVal filename As _
    String)
Dim length As Long

    On Error GoTo FileDoesntExist
    length = FileLen(filename)
    FileExistsWithFileLen = True
    Exit Function
    
FileDoesntExist:
    FileExistsWithFileLen = False
End Function

Private Function FileExistsWithAttrib(txt)
Dim lRetVal As Long
    
    On Error GoTo FileDoesntExist:
    lRetVal = GetAttr(txt)
    FileExistsWithAttrib = True
    Exit Function
    
FileDoesntExist:
    FileExistsWithAttrib = False
End Function
 
Formatted by Neil Crosby
 
 
Copyright © 1997-2003 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated