home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol291 / dir.inc < prev    next >
Encoding:
Text File  |  1986-12-22  |  1.5 KB  |  67 lines

  1. function Dir(Drive: char): integer;
  2.   { This program will give a directory of specified drive.
  3.     And returns the number of files on that drive }
  4. const
  5.   Search_First  = 17;
  6.   Search_Next   = 18;
  7.   Set_DMA       = 26;
  8.  
  9. var
  10.   First: Boolean;
  11.   Count, Total,
  12.   Result, Loop, Start : Integer;
  13.   FCB                 : array[0..35] of Byte;
  14.   DMA                 : array[0..127] of Byte;
  15.   ch : char;
  16.  
  17. begin
  18.   First:= True;
  19.   Count:= 0;
  20.   Total:= 0;
  21.   Result := BDos(Set_DMA,Addr(DMA));
  22.   fillchar(FCB,sizeof(FCB),0); { fill FCB with 0}
  23.   fillchar(FCB,12,'?'); {now make FCB 0 to 11 = ?}
  24.   if Drive in ['A'..'P'] then  FCB[0] := ord(Drive) - $40  {select the drive}
  25.     else FCB[0] := 0; {if not in range use the default drive}
  26.   repeat
  27.   if First then
  28.      begin
  29.        First := false;
  30.        write('   ');
  31.        Result := BDos(Search_First,Addr(FCB));
  32.      end
  33.   else
  34.     Result := BDos(search_Next);
  35.  
  36.     Start := Result * 32;
  37.     if Result <> 255 then begin
  38.       for Loop:= Start to start+8 do
  39.         Write(Char(DMA[Loop]and 127)); {and 127 to reset bit 8}
  40.       Write('.');
  41.      for Loop:= Start+9 to Start+11 do begin
  42.        ch := Char(DMA[Loop]);
  43.        if ch > '~' then begin
  44.          lowvideo;
  45.          write(Char(ord(ch)and 127));
  46.          normvideo;
  47.        end else write(ch);
  48.      end;
  49.  
  50.     if Count < 4 then begin
  51.        Count := Count + 1;
  52.        Write(' | ');
  53.       end
  54.     else begin
  55.        WriteLn;
  56.        write('   ');
  57.        Count := 0;
  58.       end;
  59.  
  60.     Total := Total + 1;
  61.   end;
  62.  until Result=255;
  63.  if count <> 0 then writeln;
  64.  Dir := Total;
  65. end; { of function Dir }
  66.  
  67.