directory tree -> array

Bob Sneidar bobsneidar at iotecdigital.com
Mon Feb 3 18:51:55 EST 2020


Yes, but I couldn't get the recursion working right. My brain fried. 

Bob S


> On Feb 3, 2020, at 11:18 , Ben Rubinstein via use-livecode <use-livecode at lists.runrev.com> wrote:
> 
> On 22/01/2020 18:26, Richard Gaskin via use-livecode wrote:
>> We have many handlers that deliver directory trees as lists, but arrays are a different beast.  Because the depth is both unknowable and varied, I can't think of a way to do this without resorting to "do".
> 
> Surely this is what recursion does for you?
> 
> e.g.
> 
> function directoryTreeAsArray tRoot, tSubPath --> aTree
>   local aTree
>   set the defaultFolder to tRoot & "/" & tSubPath
>   put the files into aTree["files"]
>   repeat for each line f in the folders
>      if char 1 of f = "." then next repeat -- unix gotcha
>      put directoryTreeAsArray(tRoot, tSubPath & "/" & f) into aTree["folders"][f]
>   end repeat
>   return aTree
> end directoryTreeAsArray
> 
> (initially invoked with empty second parameter)
> 
> Or have I misunderstood the requirement?





More information about the use-livecode mailing list