|
|
Title | See if a file exists four ways |
Keywords | file, exists |
Categories | Files and 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
|
|
|
|
|
|