Domino on Linux/Unix, Troubleshooting, Best Practices, Tips and more ...

alt

Daniel Nashed

Lotus Script - Check if a file or folder exists

Daniel Nashed – 13 December 2024 11:23:34

There isn't a direct function in Lotus Script to check if files exist.
Most of us have written a function like this multiple times as a helper.

I am working on an application which will be available as open source soon and I needed one again...
Here is a version of a check function, which should cover all cases and might be useful for you too.
It doesn't handle hidden files -- I know. But I didn't want to add that logic.

-- Daniel


Function FileFolderExists (FileName As String) As Long
       
        'Returns
        '  2 = Directory exists
        '  1 = File exists
        '  0 = File/Directory does not exist
        ' -1 = Directory for file does not exist
        ' -2 = Other error
       
        Dim result As String

        FileFolderExists = -2
        On Error GoTo ErrorHandler
       
        result = Dir$(FileName, 16)
       
        If (result = "") Then
                FileFolderExists = 0
                Exit Function
        End If
       
        result = Dir$(FileName, 0)
       
        If (result = "") Then
                FileFolderExists = 2
        Else
                FileFolderExists = 1
        End If
       
        Exit Function
       
ErrorHandler:
       
        If (76 = Err) Then
                FileFolderExists = -1
        End If
       
        Exit Function
       
End Function


Comments

1Palmi   13.12.2024 13:19:03  Lotus Script - Check if a file or folder exists

this would find hidden files , ? would it ?

Function FileFolderExists(FileName As String) As Long

Dim result As String

FileFolderExists = -2

On Error GoTo ErrorHandler

' Check for hidden files and directories

result = Dir$(FileName, vbHidden Or vbDirectory)

If (result = "") Then

FileFolderExists = 0

Exit Function

End If

' Check if it's a directory

If (GetAttr(FileName) And vbDirectory) = vbDirectory Then

FileFolderExists = 2

Else

FileFolderExists = 1

End If

Exit Function

ErrorHandler:

If (Err.Number = 76) Then

FileFolderExists = -1

End If

Exit Function

End Function

Links

    Archives


    • [HCL Domino]
    • [Domino on Linux]
    • [Nash!Com]
    • [Daniel Nashed]