home *** CD-ROM | disk | FTP | other *** search
- program STI_DXRF; { utility to print the tree }
- { of the disk }
- uses
- STI_ERR,
- Dos; { standard dos unit }
-
- type
- BuffPtr = ^Buffer; { pointer to a buffer }
- Buffer = record { the actual record }
- Name : string[13];
- Attr : byte;
- Left : BuffPtr;
- Right : BuffPtr;
- end;
-
- var
- Head : BuffPtr; { head of the tree }
- Drive : string[3]; { current drive }
- Path : string; { current path }
- FindRec : SearchRec; { record for searching }
- PrintString : String; { output string }
- Done : boolean; { end flag }
-
- NoDirs : word; { number of directories }
- NoFiles : word; { number of files }
- FreeSpace : longint; { how much free disk space }
- Size : longint; { size of the disk }
-
- {---------------------------------------------------------------------------}
-
- procedure GetFiles(Var List : Buffer); { read file list }
-
- Var
- OldPath : string; { old path }
- OldRec : SearchRec; { old search record }
-
- begin
- While(DosError = 0) do { loop until no files }
- begin
- List.Name := FindRec.Name; { assign name to the buffer }
- List.Attr := FindRec.Attr; { assign attribute to the buffer}
- if (FindRec.Attr = 16) then { is it a directory }
- begin
- Inc(NoDirs); { yes, inc the counter }
- if (FindRec.Name <> '.') and (FindRec.Name <> '..') then
- begin { it is a child }
- List.Name := List.Name+'\'; { so we want to start a new }
- OldPath := Path; { branch on the tree }
- Path := Path + List.Name;
- List.Left := NIL;
- New(List.Right); { directories branch to the }
- List.Right^.Name := ''; { right. then we set up a new }
- List.Right^.Attr := 0; { record for findfirst }
- List.Right^.Left := NIL;
- List.Right^.Right := NIL;
- OldRec := FindRec;
- FindFirst(Drive+Path+'*.*',AnyFile,FindRec); { check for files}
- GetFiles(List.Right^); { note the recursion here }
- New(List.Left); { we first traverse the files in}
- List.Left^.Name := ''; { the directory so we go right }
- List.Left^.Attr := 0; { note that this is the NEW }
- List.Left^.Left := NIL; { directory list }
- List.Left^.Right := NIL;
- Path := OldPath;
- FindRec := OldRec;
- FindNext(FindRec);
- GetFiles(List.Left^); { continue in the directory }
- end;
- FindNext(FindRec); { get the next one }
- end
- else
- begin
- Inc(NoFiles); { this is not a directory so }
- New(List.Left); { we boogy of on the left node }
- List.Left^.Name := '';
- List.Left^.Attr := 0;
- List.Left^.Left := NIL;
- List.Left^.Right := NIL;
- FindNext(FindRec); { and we get the next file }
- GetFiles(List.Left^); { then do a recursive call }
- end;
- end;
- end;
-
- {---------------------------------------------------------------------------}
-
- procedure TraversePrint(List : Buffer); { print the tree }
-
- begin
- while ((List.Left <> NIL) or (List.Right <> NIL)) and not(Done) do
- begin
- if List.Attr = 16 then
- begin
- writeln(PrintString,copy('--------------',1,13-length(List.Name)),
- List.Name,'<sub directory>');
- PrintString := PrintString + ' |';
- TraversePrint(List.Right^);
- WriteLn(PrintString);
- PrintString := copy(PrintString,1,length(PrintString)-7);
- WriteLn(PrintString);
- if List.Left <> NIl then
- begin
- Done := FALSE;
- TraversePrint(List.Left^);
- end;
- end
- else
- if (List.Left <> NIL) and not(Done) then
- begin
- writeln(PrintString,copy('--------------',1,13-length(List.Name)),List.Name);
- TraversePrint(List.Left^);
- end;
- end;
- Done := TRUE;
- end;
-
- {---------------------------------------------------------------------------}
-
- procedure Do_Index; { this is where we start }
-
- begin
- FindFirst(Drive+Path+'*.*',AnyFile,FindRec); { get the first file }
- New(Head); { allocate and initialise }
- Head^.Name := ''; { the tree root }
- Head^.Attr := 0;
- Head^.Left := NIL;
- Head^.Right := NIL;
- GetFiles(Head^); { then we get all the files }
- WriteLn;
- WriteLn(' DISKXREF Version 1.0');
- WriteLn(' Copyright (C) 1990,1991 by Software Technology International');
- WriteLn(' All Rights Reserved');
- WriteLn;
- WriteLn;
- WriteLn;
- WriteLn('Structure of Drive : ',Drive);
- WriteLn;
- Write('Number of Directories : ',NoDirs:7,' ');
- WriteLn('Number of Files : ',NoFiles);
- Write('Disk Size : ',Size:7, ' bytes ');
- WriteLn('Free Space On Disk : ',FreeSpace,' bytes');
- WriteLn;
- WriteLn('\ <root directory>');
- Done := FALSE;
- TraversePrint(Head^); { and print the tree }
- end;
-
- {---------------------------------------------------------------------------}
-
- procedure Usage; { messages for those out of the }
- { know }
- begin
- WriteLn;
- WriteLn('Usage : DISKXREF <drive>');
- WriteLn;
- Halt;
- end;
-
- {---------------------------------------------------------------------------}
-
- function ValidateDrive(DriveString : string) : string; { check drive string }
-
- begin
- DriveString[1] := UpCase(DriveString[1]);
- if DriveString[1] in ['A'..'Z'] then
- begin
- FreeSpace := DiskFree(ord(DriveString[1])-64);
- Size := DiskSize(ord(DriveString[1])-64);
- if (FreeSpace < 0) or (Size < 0) then
- begin
- WriteLn('Illegal Drive : ',DriveString[1],':');
- Halt;
- end;
- ValidateDrive := DriveString[1]+':'
- end
- else
- begin
- Writeln('Invalid Drive : Must be A to Z');
- Halt;
- end;
- end;
-
- {---------------------------------------------------------------------------}
-
- begin { program body }
- NoDirs := 0;
- NoFiles := 0;
- Drive := '';
- Path := '\';
- PrintString := '|';
- if ParamCount < 1 then { check the # of params }
- Usage;
- Drive := ValidateDrive(ParamStr(1)); { chec for a legal drive }
- Do_Index; { boogy !! }
- end.
-