Just a quick tip/reminder to anyone out there who may have had to use the LotusScript (nee VisualBasic) Dir()
or Dir$()
function. The function IS NOT reentrant. If, as is a typical use-case, you want to deep traverse a directory tree by recursively calling a function that examines a directory using the Dir()
function, take care not to nest calls within the recursion. For example:
Function traverse(searchMe$) dirName$ = Dir$(searchMe$, ATTR_DIRECTORY%) Do While dirName$ <> "" If Not(dirName$ = ".") And Not(dirName$ = "..") Then If Getattr(searchMe$ & delim$ & dirName$) = ATTR_DIRECTORY% then traverse(searchMe$ & delim$ & dirName$) End If dirName$ = Dir$() Loop 'do something print dirName$ End Function
Would be incorrect as the nested Dir
call would advance the pointer for the caller’s Dir()
. The correct usage to perform this task would be to build the complete list before making the recursive call, like so:
Function traverse(searchMe$) dirName$ = Dir$(searchMe$, ATTR_DIRECTORY%) Dim dirList List As Integer Do While dirName$ <> "" If Not(dirName$ = ".") And Not(dirName$ = "..") Then If Getattr(searchMe$ & delim$ & dirName$) = ATTR_DIRECTORY% Then dirList(dirName$) = 1 End If dirName$ = Dir$() Loop 'now we can loop and recurse through the list Forall de In dirList Call traverse(searchMe$ & delim$ & Listtag(de)) End Forall 'do something Print searchMe$ End Function
Note to Lotus: While this may be obvious to some, it wouldn’t hurt to document this in the Designer help file. Also a quick shout out to Jeff Dayton for reminding me about the runtime security level setting in the security tab of the Agent Infobox. What can I say? I get old, I forget things.
Also, check out David Leedy’s latest episode (#5) of his entertaining and informative Notes in Nine screencasts. It’s about time the LotusScript editor got some love!