I struggle with recursion and have a recursive handler, that Ken Ray of Sons of Thunder published, that I would like to refactor. At present the handler works well but it saves data to a script local variable which I access via a second function. I would like to convert the handler to a function but my own attempts have given odd results so I have binned them. Here is the original script along with two helper functions.
Code: Select all
local sListOfFolders
on GetListOfFolders whatFolder
set the defaultFolder to whatFolder
put whatFolder & return after sListOfFolders
put the folders into tDirList
repeat with n = 2 to the number of lines of tDirList
GetListOfFolders (whatFolder & "/" & (line n of tDirList))
end repeat
end GetListOfFolders
Function FoldersFound
If the last char of sListOfFolders is cr then delete the last char of sListOfFolders
return sListOfFolders
end FoldersFound
On ZeroFoldersFound
put empty into sListOfFolders
end ZeroFoldersFound
Thanks for reading.