const
STACK_SIZE = 500;
type
mystack = array[1..STACK_SIZE] of TFileName;
var
drive: string;
fileinput: string;
found_count: longint;
thestack: mystack;
stackcount: longint;
maxstack: longint;
procedure listdirsizes(filedir: TFileName);
{ iterative. Uses "thestack" to place directories to work on.
then main proc pulls them off to work on }
var
f: TFileName;
fileinfo, dirinfo: TSearchRec;
retcode: longint;
begin
f := filedir + '\*.*';
retcode := FindFirst(f, faAnyFile-faVolumeID, dirinfo);
while retcode = 0 do
begin
{ is this a directory listing? }
if (dirinfo.attr and faDirectory = faDirectory) then
begin
if (dirinfo.name <> '.') and (dirinfo.name <> '..') then
begin
inc(stackcount);
if stackcount > maxstack then
maxstack := stackcount;
thestack[stackcount] := filedir + '\' + dirinfo.name;
end;
end
else
{ if not, is this my file I'm looking for? }
if (upstr(dirinfo.name) = fileinput) then
begin
writeln('Found: ', filedir + '\' + dirinfo.name);
inc(found_count, 1);
end;
retcode := FindNext(dirinfo);
end;
FindClose(dirinfo);
end;
procedure listdrive(filedir: TFileName);
{ main driver for file search - calls listdirsizes to do work
for each directory }
begin
stackcount := 0;
found_count := 0;
listdirsizes(filedir);
repeat
filedir := thestack[stackcount];
dec(stackcount);
listdirsizes(filedir);
until stackcount = 0;
writeln;
writeln(found_count, ' files found.');
writeln('Maximum stack was: ', maxstack, ' out of ', STACK_SIZE,
' elements.');
end;