Board index » delphi » how to build up a tree?

how to build up a tree?

I'm searching for a procedure which builds up a database including the whole drive-tree:

 C:
 - dos
 - windows
..

I tried to contruct an algorithm but i failed !

 Cheers

 Frederic , EASTWARDS

----------------------------------------
## FREDERIC BITSCH PRIVATE PROGRAMMER ##
----------------------------------------

 

Re:how to build up a tree?


Quote
frede...@fbitsch.inka.de (Frederic Bitsch) wrote:
>I'm searching for a procedure which builds up a database including the whole drive-tree:
> C:
> - dos
> - windows
>..

Try using a recursive solution.

Re:how to build up a tree?


Quote
In article <52k2e7$...@nz12.rz.uni-karlsruhe.de> frede...@fbitsch.inka.de (Frederic Bitsch) writes:
>I'm searching for a procedure which builds up a database including the whole drive-tree:
> C:
> - dos
> - windows
>..
>I tried to contruct an algorithm but i failed !

Keep working at it.  The solution lends itself naturally to recursive
descent... but the file-search primitives might not!  Here is another idea.

Begin with the root directory and scan it.  Each time you find a file, log it.
Each time you find a directory, put it on a stack or a queue.  When you reach
the end of the current directory, pop a directory name off the stack or queue
and scan it as before.  When the stack or queue is empty you are done.

The latter algorithm should be compatible with the Dos "FindFirst" and
"FindNext" implementation -- which as you may have discovered can only do a
limited number of finds.

/mr/

Re:how to build up a tree?


Basically what you have to do is use some temp files to hold
listings.

Start with the FindFirst/FindNext routine to search the root dir.
Create a temp file to hold that list.

Next, run FindFirst/FindNext again, loading the path parameter with
the dir names in the temp file, and append the results to the
end of the file.

Continue repeating the FindFirst/FindNext routine for each
entry in the temp file. It will get progressively
slower as it goes on, but should take only a minute or two
to log the entire drive.

Just be sure to skip the . .. entries it returns.

Kinda simple, but works.

--
------------------------------------------------------
Jeffrey L. Meyer, Owner-MeySoft    jmey...@meysoft.com
http://www.meysoft.com
------------------------------------------------------

Other Threads