home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / GF100.ZIP / GF.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1988-11-05  |  6.7 KB  |  215 lines

  1. uses crt,dos;
  2.  
  3.   type
  4.     dtstr = string[20];
  5.     attrstr = string[6];
  6.     str2 = string[2];
  7.  
  8.   var
  9.     lcount,fcount : word;
  10.     fsize : longint;
  11.     path,origpath,mask : string;
  12.     sdrive : str2;
  13.     ch : char;
  14.  
  15.   procedure docopyright;
  16.     begin
  17.       writeln('GF - Get File, (C) Copyright 1988, Basil Groman',#10)
  18.     end;
  19.  
  20.   procedure init;
  21.  
  22.    (*  Initializes Variables *)
  23.  
  24.     var
  25.       test : integer;
  26.     begin
  27.       fcount := 0;
  28.       lcount := 25-whereY;
  29.       fsize := 0;
  30.       getdir(0,path);
  31.       test := pos(':',mask);
  32.       if test <> 0 then          { If a particular drive was specified }
  33.         begin
  34.           sdrive := copy(mask,pred(test),2);
  35.           delete(mask,1,2);
  36.         end
  37.       else                       { Else use current drive }
  38.         sdrive := copy(path,pred(pos(':',path)),2);
  39.       sdrive[1] := upcase(sdrive[1]);
  40.     end;
  41.  
  42.   function PadZero(num : integer):str2;
  43.  
  44.     (* Takes an integer value and returns a 2 character string )
  45.     (  with the first character a '0' if the number was less   )
  46.     (  than 10.  This function only works with numbers with 2  )
  47.     (  digits or less.                                        *)
  48.  
  49.     var
  50.       temp : str2;
  51.     begin
  52.       str(num:2,temp);
  53.       if num < 10 then
  54.         temp[1] := '0';
  55.       PadZero := temp;
  56.     end;
  57.  
  58.   function timedate(it:longint):dtstr;
  59.     (* This function takes the value returned in SearchRec.Time )
  60.     (  and fills a string with Time and Date information to be  )
  61.     (  displayed on the screen.                                *)
  62.     var
  63.       dt : datetime;
  64.       temp : dtstr;
  65.     begin
  66.       unpacktime(it,dt);
  67.       with dt do
  68.         timedate := PadZero(hour)+':'+PadZero(min)+':'+PadZero(sec)+'   '+
  69.                 PadZero(month)+'/'+PadZero(day)+'/'+PadZero(year-1900);
  70.     end;
  71.  
  72.   function attributes(attr : byte):attrstr;
  73.     (* This function takes the value in SearchRec.Attr and fills )
  74.     (  a string with attribute information to be displayed on    )
  75.     (  the screen.                                              *)
  76.     var
  77.       temp : attrstr;
  78.     begin
  79.       temp := '      ';
  80.       if attr and $01 <> 0 then
  81.         temp[1] := 'R'
  82.       else
  83.         temp[1] := '-';
  84.       if attr and $02 <> 0 then
  85.         temp[2] := 'H'
  86.       else
  87.         temp[2] := '-';
  88.       if attr and $04 <> 0 then
  89.         temp[3] := 'S'
  90.       else
  91.         temp[3] := '-';
  92.       if attr and $08 <> 0 then
  93.         temp[4] := 'V'
  94.       else
  95.         temp[4] := '-';
  96.       if attr and $10 <> 0 then
  97.         temp[5] := 'D'
  98.       else
  99.         temp[5] := '-';
  100.       if attr and $20 <> 0 then
  101.         temp[6] := 'A'
  102.       else
  103.         temp[6] := '-';
  104.       attributes := temp;
  105.     end;
  106.  
  107.   procedure incrline;
  108.     (* This procedure keeps track of how many lines have have been )
  109.     (  written to the screen and pauses when screen is full.      *)
  110.     begin
  111.       inc(lcount);
  112.       if lcount > 23 then               { If screen is full }
  113.         begin
  114.           write('   <--- More --->');
  115.           ch := readkey;                { Pause til key is pressed }
  116.           if ch = #27 then              { If <Esc> was pressed }
  117.             begin                       { allow user to stop program }
  118.               writeln(#10,fcount,' files found at ',fsize,' total bytes');
  119.                             { ^  Tell what it's found so far ^ }
  120.               halt(0);             { Stop  program }
  121.             end;
  122.           writeln;           { Otherwise business as usual }
  123.           lcount := 0
  124.         end;
  125.     end;
  126.  
  127.   procedure writeEntry(srec :searchrec);
  128.     (* This procedure formats the File info returned in SearchRec )
  129.     (  and writes the line to the screen.                        *)
  130.     begin
  131.       write('','   ',srec.name);
  132.       gotoxy(20,whereY);
  133.       if srec.attr and $18 = 0 then
  134.         writeln('',srec.size : 7,' bytes     ',timedate(srec.time),
  135.                 '    ',attributes(srec.attr))
  136.       else
  137.         if srec.attr and $10 <> 0 then
  138.           writeln('','< DIR >':13,'     ',timedate(srec.time),
  139.                 '    ',attributes(srec.attr))
  140.         else
  141.           writeln('','<Volume_ID>':13,'     ',timedate(srec.time),
  142.                 '    ',attributes(srec.attr));
  143.       incrline
  144.     end;
  145.  
  146.   procedure getfiles(path,mask : string);
  147.     (* This procedure finds all files in a directory matching the )
  148.     (  mask and lists them on the screen.                        *)
  149.     var
  150.       srec : searchrec;
  151.       ch : char;
  152.     begin
  153.       if path <> '' then                       { If Root Directory }
  154.         findfirst(sdrive+'\'+path+'\'+mask,$FF,srec)
  155.       else                                     { Any Other Directory }
  156.           findfirst(sdrive+path+'\'+mask,$FF,srec);
  157.       if doserror = 0 then
  158.         begin
  159.           writeln;
  160.           incrline;
  161.           writeln(sdrive+'\'+path);          { Directory being searched }
  162.           incrline
  163.         end;
  164.       while doserror = 0 do                  { List Files }
  165.         begin
  166.           inc(fcount);
  167.           inc(fsize,srec.size);
  168.           writeEntry(srec);
  169.           findnext(srec);
  170.         end;
  171.     end;
  172.  
  173.   procedure finddirs(path : string;mask:string);
  174.     (* This procedure finds all directories and searches for )
  175.     (  files in each that match mask.                       *)
  176.     var
  177.       srec : searchrec;
  178.       temp : string;
  179.     begin
  180.       findfirst(sdrive+'\'+path+'*.',$12,srec);   {  Find first Dir }
  181.       while doserror = 0 do
  182.         begin
  183.           if (srec.name <> '.') and (srec.name <> '..') and
  184.              ((srec.attr and $12) <> 0) then      {  If a New Dir }
  185.             begin
  186.               temp := path+Srec.name;
  187.               getfiles(temp,mask);         { Check for mask matching files }
  188.               finddirs(temp+'\',mask);        { Recursive call to find }
  189.                                               { other directories in this}
  190.                                               { one}
  191.             end;
  192.           findnext(srec);
  193.         end;
  194.     end;
  195.  
  196.          {  \/      Main  Program     \/ }
  197.   begin
  198.     docopyright;
  199.     if paramcount <= 0 then          {  If no parameters were specified }
  200.       begin
  201.         write ('Enter Search Spec: ');
  202.         readln(mask);
  203.       end
  204.     else                             { Else go ahead }
  205.       mask := paramstr(1);
  206.     init;
  207.     writeln('Searching Drive -> ',sdrive);
  208.     getfiles('',mask);               { Check Root Directory }
  209.     finddirs('',mask);               { Check the rest       }
  210.     if fcount <> 0 then
  211.       writeln(#10,fcount,' files found at ',fsize,' total bytes')
  212.     else
  213.       writeln(#10,'No files found');
  214.   end.
  215.