The Directory Walker revisited

David Vaughan dvk at dvkconsult.com.au
Fri Sep 5 19:56:01 EDT 2003


On Saturday, Sep 6, 2003, at 05:11 Australia/Brisbane, Wouter 
<wouter.abraham at pi.be> wrote:
> Hi,
>
> As I already unintentionally treaded some toes in this thread, please 
> put on the metal tipped safety shoes for the following, because now I 
> am puzzled...ect;

> Following are the puzzling lines:
>
>> the recursion involved only reaches the depth
>> of the directory structure. So if your folders are nested twenty deep,
>> the greatest recursion depth will be twenty as well. It doesn't matter
>> how "wide" the directory structure is, just how deep.
>
> I hope this is your code (anyway the recursive ones kind of all boil 
> down to this):
>
> on directoryWalk whatFolder
>   set the defaultFolder to whatFolder
>   put the files into temp
>   repeat for each line x in temp
>     put whatFolder & "/" & x & return after gHierList
>   end repeat
> #### here it gets a list of directories in the whatFolder directory
>  put the folders into tDirList
> #### and here it starts recursing for each line in the tDirlist
> #### and does the same for each recursion
>   repeat with x =  2 to the number of lines of tDirList
>     directoryWalk (whatFolder & "/" & (line x of tDirList))
>   end repeat
> end directoryWalk
>
> So can you enlighten me on the following;
>
>> So if your folders are nested twenty deep, the greatest recursion 
>> depth will be twenty as well.
>
> I can see that the "depth" attained will be equal to twenty in this 
> case.
>
>> It doesn't matter how "wide" the directory structure is, just how 
>> deep.
>
> But as far as I can see the total amount of recursions to attain this 
> depth will be far greater than 20, because it recurses on every folder 
> it encounters on its quest to the deepsest level. To me this means 
> that wideness in this handler does matter.
> May be the problem is only in the terminology.
>
WA

Not in the terminology but in reading of recursive code. The process 
above is indeed depth-first and will recurse only to the maxDepth. The 
next folder at the same level will not be processed until all lower 
folders have been processed, and that statement is of course 
(recursively) true for each lower folder. Thus, depth matters, breadth 
is irrelevant. You can test this by walking a small tree while 
displaying depth and breadth in real time.

If the processing were post-order rather than pre-order then breadth 
would count but in Geoff's and my code it does not. I think this is 
where the principal confusion has arisen.

regards
David

> Hoping not to have mashed toes, greetings and thanx to all that 
> participated in this thread,
> Yours puzzling,
> WA




More information about the use-livecode mailing list