Link to home
Start Free TrialLog in
Avatar of madmare
madmareFlag for Israel

asked on

check file exist

Hi,
 How to check if file Exist (VB6) ?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kaliyugkaarjun
kaliyugkaarjun

Function FileExists(FileName As String) As Boolean
    On Error GoTo ErrorHandler
    ' get the attributes and ensure that it isn't a directory
    FileExists = (GetAttr(FileName) And vbDirectory) = 0
ErrorHandler:
    ' if an error occurs, this function returns False
End Function

 OR another way

 Function FileExist(sTestFile As String) As Boolean
    Dim lSize As Long
    On Error Resume Next
    'Preset length to -1 because files can be zero bytes in length
    lSize = -1
    'Get the length of the file
    lSize = FileLen(sTestFile)
    If lSize > -1 Then
        FileExist = True
    Else
        FileExist = False
    End If
End Function