Recursive directory tree reading 
Author Message
 Recursive directory tree reading

> Marco Quezada a crit dans le message ...
> >Hello all,

> >I am writing a routine in C that will load a directory tree
> >structure.

> The C language does not know what a directory is.

> >It is similar to the tree command in linux but specific to my
> >needs do
> >I can't and don't want to use that source. So far I've had some
> >trouble so I was wondering if anyone else has tried something like
> >this and could point me to a reference or give a source example.

> Your C compiler, that is dedicated to your machine+OS combination,
> has probably an extension for that. Read the manual, there is
> probably an example. If you are stuck, ask in a newsgroup dedicated
> to your machine+OS+compiler.

> Personal opinion: Avoid recursivity.

> - It makes hard to read, debug and maintain programs.
> - It makes program that are dependend from the size of the
>   automatic memory.
> - There is no way to prevent a crash against a too small
>   automatic memory.

I think this represents a fairly common C design problem, i.e. a
naturally recursive system that MAY need fairly large storage in
SOME instances.  This is typical of directory structures, where
many have only a few entries, and a few may have hundreds or more.

I have handled this in the past with something like:

int recurse(int param)
   while (whatever) {
      sz = computelocalsizeneeded()
      ptr = malloc(sz);


Which gets the large storage out of the (possibly limited) stack,
and maintains the clarity of recursive solution.  Everything
remains nicely re-entrant.

The localsize/malloc may be handled by building a locally headed
list, and the free operation would have to walk the list to free it.

IMHO too many people reject a query because it is fairly specific,
and thus appears to be off topic.  Abstracting things is instructive.



Wed, 09 Apr 2003 13:01:41 GMT  
 [ 1 post ] 

 Relevant Pages 

1. Recursive directory tree reading

2. Reading a directory tree recursively

3. Showing Directory Tree in a Tree Ctrl

4. Showing Directory Tree in a Tree Ctrl

5. c-tree, reading files, understaing c-tree

6. Recursive/nested data type (similar to data tree)

7. Exercise about binary tree and recursive functions

8. HELP!: non-recursive binary tree inorder traversal algorithm

9. How to recursive all file in directory

10. How can recursive all file in a directory

11. Recursive Directory Processing

12. Recursive directory listing in Win2K


Powered by phpBB® Forum Software