directory tree -> array

Ben Rubinstein benr at cogapp.com
Mon Feb 3 14:18:55 EST 2020


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