IOsFileExist




Attribute VB_Name = "FileTest"
Option Explicit

Public Function IsFile(FileString As String) As Boolean
Dim FileNumber As Integer
On Error Resume Next
FileNumber = FreeFile()
Open FileString For Input As #FileNumber
If Err Then
IsFile = False
Exit Function
End If
IsFile = True
Close #FileNumber
End Function

Sub Main()
MsgBox "IsFile(""C:\Windows\Explorer.exe"") = " _
& IsFile("C:\Windows\Explorer.exe") & _
" and IsFile(""C:\Windows\Explorer.err"") = " & _
IsFile("C:\Windows\Explorer.err") & ".", , "IsFile Function"
End Sub

Function FileExists% (FullPathAndFile$)
On Error Resume Next
If FileLen(FullPathAndFile) > 0& Then
If Err = 0 Then FileExists = True
End If
End Function

Public Function FileExists(FullPathAndFile$) As Boolean
'The file could exist, but not have anything in it.

'End If'> 0& Then 'if

On Error Goto ErrHandler
Call FileLen(FullPathAndFile)
ErrHandler:
If Err = 0 Then FileExists = True
End Function

Public Function FileExists(filename As String) As Integer
Dim x As Integer
On Error Resume Next
x = Len(Dir(filename))
If Err Or x = 0 Then
FileExists = False
Else
FileExists = True
End If

End Function
Inputs:
Full path and filename of file to be tested.

Returns:True or False
Assumes:To see how this function works paste code into notepad
and name it FileTest.bas.
Run the module from Sub Main()












( iosfileexist.html )- by Paolo Puglisi - Modifica del 17/12/2023