home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / TURBOPAS / TPGET.ZIP / DIRSRCH.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1984-11-22  |  2.8 KB  |  94 lines

  1. {$v-}
  2.  
  3.  program dirsrch;
  4. { This program will search a directory for a matching file name
  5.   and then print out it along with its size and attribute byte.
  6.   Other information is available in the record `dta_def'. Using
  7.   the same techniques, if the entry is a directory, it could be
  8.   saved and then searched recursively.
  9.  
  10.          Jim Holtman
  11.          35 Dogwood Trail
  12.          Randolph, NJ 07869
  13.          (201) 361-3395
  14. }
  15.  
  16.     type
  17.        regset = record
  18.           ax,bx,cx,dx,bp,si,di,ds,es,flags : integer;
  19.           end;
  20.        fname = array[1..80] of char;
  21.        str80 = string[80];
  22.        dta_def = record
  23.           filler : array[1..21] of byte;
  24.           attribute : byte;
  25.           file_time : integer;
  26.           file_date : integer;
  27.           file_size : array[1..2] of integer;
  28.           file_name : fname;
  29.           end;
  30.  
  31.     const
  32.        carry = 1;
  33.  
  34.     var
  35.        dta : dta_def;
  36.        param : regset;
  37.        s_string : string[70];
  38.        pattern : string[40];
  39.        r1,r2 : real;
  40.        dir_name : str80;
  41.        dir_return : array[1..64] of char;
  42.  
  43.     function pack_name(var a1;
  44.          size : integer) : str80;
  45.  
  46.        var
  47.           i : integer;
  48.           b : str80;
  49.           a : array[1..1000] of char absolute a1;
  50.  
  51.        begin
  52.           i := 1;
  53.           b := '';
  54.           while (a[i]<>chr(0)) and (i <= size) do begin
  55.              b := b+a[i];
  56.              i := i+1;
  57.              end;
  58.           pack_name := b;
  59.           end;
  60.  
  61.     begin
  62.        with param,dta do begin
  63.           write('Pattern to search for - ');
  64.           readln(pattern);
  65.           pattern := pattern+chr(0);
  66.           ax := $1A00;             {set DTA}
  67.           ds := seg(dta);
  68.           dx := ofs(dta);
  69.           msdos(param);
  70.           dx := ofs(pattern[1]);
  71.           ax := $4E00;             {find 1st}
  72.           cx := $FF;
  73.           msdos(param);
  74.           while (flags and carry) = 0 do begin
  75.              s_string := pack_name(file_name,sizeof(file_name));
  76.              r1 := file_size[1];
  77.              r2 := file_size[2];
  78.              if r1 < 0 then r1 := r1+65536.0;
  79.              if r2 < 0 then r2 := r2+65536.0;
  80.              writeln(s_string,'':(16-length(s_string)),(r2*65536.0+r1):8:0,
  81.                   attribute:6);
  82.              ax := $4F00;
  83.              msdos(param);
  84.              end;
  85.           dx := 0;
  86.           ds := dseg;
  87.           si := ofs(dir_return);
  88.           ax := $4700;             {get the current directory}
  89.           msdos(param);
  90.           dir_name := '\'+pack_name(dir_return,sizeof(dir_return));
  91.           writeln('Current directory is ',dir_name);
  92.           end;
  93.        end.
  94.