1

This seems like the most basic of things. There are lots of examples on google, all of which I have put into my code and have gotten the same result.

I beleive I am missing something specific to the language, and it's really getting irritating.

Given

pathName$ = "..\..\images\" + artID + "\" + artNum + "\"
    dirTest$ = "..\..\images\" + artID + "\"
    If Dir$(pathName$ , ATTR_DIRECTORY) = "" Then
        MsgBox "No Dir"
    Else
        MsgBox "Dir Found!"
    End If

(everthing is dimmed correctly)

I have put msgbox's before pathName$ and right before the DIR call, but it fails when it gets to the test. I know for a fact that the dir doesn't exist in certain scenarios, but I would like to trap the error, not have the script crash on failing to find the dir.

I have tried DIR (path,16) DIR$(path,16) DIR (path$,16) DIR$(path$,16) as well as the ATTR_DIRECTORY key word.

How can I gracefully check the existence of a directory in Lotusscript?

2 Answers 2

10

The Dir$ command will generate the run-time error code 76 if the directory does not exist. So you can trap the run-time error by adding On Error 76 Resume Next to your code:

pathName$ = "..\..\images\" + artID + "\" + artNum + "\"
dirTest$ = "..\..\images\" + artID + "\"
On Error 76 Resume Next
If Dir$(pathName$ , ATTR_DIRECTORY) = "" Then
    MsgBox "No Dir"
Else
    MsgBox "Dir Found!"
End If

Inspiration: http://searchdomino.techtarget.com/tip/Finding-files-and-directories-with-LotusScript

4
  • 1
    That website is great for some info, but the inability to quickly login and see the article stops me every time. I will try the code and post back Oct 27, 2012 at 13:39
  • 1
    You don't need to login, actually. Just page down and you will see the content. Oct 28, 2012 at 6:43
  • ATTR_DIRECTORY=16 Mar 24, 2022 at 7:45
  • Nowadays, to get around the blockage, i use the wayback machine to find technotes on sites like the searchdomino.techtarget.com etc. Oct 3, 2022 at 17:40
0

I think the better solution is to test a variant with the Dir$ function result. That's because if the dir path is completely wrong the error 76 gives back a variant containing the error. So it should be managed, like this:

`
On Error 76 GoTo PathNotValid
result = Dir$(dirPath$,16)
If result <>"" then
    MessageBox dirPath$ + " found :) "
Else
    MessageBox dirPath$ + " NOT found :( "
End if 

End:
   Exit Sub 
PathNotValid:
   MessageBox dirPath$ + " IS NOT VALID !!!"
   result = ""
   Resume Next

`

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.