In article <MPG.e90eb93b4976e33989...@news.primenet.com> of Mon, 22 Sep
1997 20:56:01 in comp.lang.pascal.borland, Mike Copeland
Quote
<mrc...@primenet.com> wrote:
I am trying to gather the file information about certain files on the
A drive. ....
Comparing your code with my URL:
http://www.merlyn.demon.co.uk/programs/listdirs.pas
- good example IMHO of how two programmers produce *similar* code for
the same job.
I think you should use a list or tree structure, but so be it. Actually
you will be using a sort of linked list of recursing stack frames.
IMHO you don't need to sort the *full* pathnames; you can contrive to
discover the names in a nearly-sorted order. (I *assume* an
alphabetical sort on full pathname is required.)
You *seem* to be saying that you'll have to sort an array containing
strings such as 'a:\d1\d2\d3\file' - ISTM that you can reduce the amount
of sorting (remember o(n log n)) and the size of the items compared and
sorted as follows; I describe a mid-stage of the recursion.
Do FindFirst/FindNext, storing the Name and Attribute fields in an array.
Sort this array, keyed on Dir-field of Attr then Name; you may want D to
sort high or low. Then scan this array, recursing into directories and
listing files. When recursing, pass in as a parameter the path-so-far,
for prepending to name for printing... you almost do anyway, and the
"\*.*" you add twice in the calls of ListAll could be added once in the
body.
This will use less stack, as only a single copy of each directory's name
is stored.
To avoid lots of little arrays, each of which has to be ample as it's
declared before you know what is wanted, declare a biggish global array
and use the remainder of it where I say "array" above. Now, you *could*
pass in not the name so far, but a list (or string) of indexes to names.
Hopefully, you've not got to worry about long file names.
HTH.
--
John Stockton, Surrey, UK. j...@merlyn.demon.co.uk Turnpike v1.12 MIME.
Web URL: http://www.merlyn.demon.co.uk/ -- includes FAQqish topics and links.
Correct 4-line sig separator is as above, a line comprising "-- " (SoRFC1036)
Before a reply, quote with ">" / "> ", known to good news readers (SoRFC1036)