home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / HOWMUCH.ZIP / HOWMUCH.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1985-07-29  |  7.7 KB  |  198 lines

  1. {|---------------------------------------------------------------------|
  2.  |    Program: HowMuch.pas.                                            |
  3.  |    Purpose: This program allows you to determine how much disk      |
  4.  |             disk space is used by groups of files.                  |
  5.  |    Example: -- Howmuch *.pas -- will compute how much diskspace     |
  6.  |             all Pascal programs use in the current directory.       |
  7.  |             Dos does not provide such a feature.  Its great         |
  8.  |             when your backing up files from a hard disk to floppies |
  9.  |             and you need to know if the files will fit on the disk. |
  10.  |    Note:    all the wild-card features of dos will work. Entering   |
  11.  |             just Howmuch will default to Howmuch *.*.               |
  12.  |             This is a simple but very valuable utility that every   |
  13.  |             every one should have. Im supprised IBM has overlooked  |
  14.  |             this need.                                              |
  15.  |    ack:     I have used the directory subroutines Staysubs.inc      |
  16.  |             from the stayre.pas collection modified to compute      |
  17.  |             disk space for each file. Author of these routines      |
  18.  |             Neil J. Rubenking.                                      |
  19.  |    Author:  Anthony Cassio of Croton Falls N.Y. [76474,231];        |
  20.  |---------------------------------------------------------------------|  }
  21.  
  22.  
  23. type
  24.   filename_type = string[64];
  25.  
  26.   regtype = record ax,bx,cx,dx,bp,si,di,ds,es,flags: integer;
  27.           end;
  28. Var
  29.   s1,s2,s3,s4,
  30.   fsize        : real;
  31.  
  32. {-----------------------------------------------------------------------------}
  33. {            G  E  T_  F  I  L  E                                             }
  34. {-----------------------------------------------------------------------------}
  35.  
  36. procedure get_file;
  37.  
  38. {****************************************************************************}
  39. {                         S T A Y S U B S  .  I N C                          }
  40. {                                                                            }
  41. {   Separate this file into "Staysubs.Inc" to provide Directory routines     }
  42. {       for the Stay-Resident Demo.                                          }
  43. {                                                                            }
  44. {****************************************************************************}
  45.  
  46.  
  47. {----------------------------------------------------------------------------}
  48. {                  F I L E         S U B R O U T I N E S                     }
  49. {----------------------------------------------------------------------------}
  50.   type
  51.     Dir_Entry   = record
  52.                       Reserved : array[1..21] of byte;
  53.                       Attribute: byte;
  54.                       Time, Date, FileSizeLo, FileSizeHi : integer;
  55.                       Name : string[13];
  56.                     end;
  57.   var
  58.     RetCode   : byte;
  59.     Filename  : filename_type;
  60.     Buffer    : Dir_Entry;
  61.     Attribute : byte;
  62. {----------------------------------------------------------------------------}
  63. {                S  E  T       Disk  Transfer  Address                       }
  64. {----------------------------------------------------------------------------}
  65. Procedure Disk_Trns_Addr(var Disk_Buf);
  66. var
  67.   Registers : regtype;
  68. Begin
  69.   with Registers do
  70.     begin
  71.       Ax := $1A shl 8;                 { Set disk transfer address to  }
  72.       Ds := seg(Disk_Buf);             { our disk buffer               }
  73.       Dx := ofs(Disk_Buf);
  74.       msdos(Registers);
  75.     end;
  76. end;
  77. {----------------------------------------------------------------------------}
  78. {                  F I N D   N E X T   F I L E   E N T R Y                   }
  79. {----------------------------------------------------------------------------}
  80. Procedure Find_Next(var Att:byte; var Filename : Filename_type;
  81.                                       var Next_RetCode : byte);
  82. var
  83.   Registers  : regtype;
  84.   Carry_flag : integer;
  85.   N          : byte;
  86.  
  87. Begin  {Find_Next}
  88.   Buffer.Name := '             ';     { Clear result buffer }
  89.   with Registers do
  90.       begin
  91.       Ax := $4F shl 8;                 { Dos Find next function }
  92.       MsDos(Registers);
  93.       Att := Buffer.Attribute;         { Set file attribute     }
  94.       Carry_flag := 1 and Flags;       { Isolate the Error flag }
  95.       Filename := '             ';
  96.       if Carry_flag = 1 then
  97.         Next_RetCode := Ax and $00FF
  98.       else
  99.         begin                          { Move file name         }
  100.         Next_RetCode := 0;
  101.         for N := 0 to 12 do FileName[N+1] := Buffer.Name[N];
  102.         s1 := lo(buffer.filesizelo);
  103.         s2 := hi(buffer.filesizelo);
  104.         s3 := lo(buffer.filesizehi);
  105.         s4 := hi(buffer.filesizehi);
  106.         end;
  107.     end;  {with}
  108. end;
  109. {----------------------------------------------------------------------------}
  110. {              F I N D   F I R S T   F I L E   F U N C T I O N               }
  111. {----------------------------------------------------------------------------}
  112. Procedure Find_First (var Att: byte;
  113.                       var Filename: Filename_type;
  114.                       var RetCode_code : byte);
  115.  
  116.   var
  117.       Registers        :regtype;
  118.       Carry_flag       :integer;
  119.       Mask, N          :byte;
  120.  
  121.   begin
  122.     Disk_Trns_Addr(buffer);
  123.     Filename[length(Filename) + 1] := chr(0);
  124.     Buffer.Name := '             ';
  125.     with Registers do
  126.       begin
  127.       Ax := $4E shl 8;                  { Dos Find First Function }
  128.       Cx := Att;                        { Attribute of file to fine }
  129.       Ds := seg(Filename);              { Ds:Dx Asciiz string to find }
  130.       Dx := ofs(Filename) + 1;
  131.       MsDos(Registers);
  132.       Att := Buffer.Attribute;          { set the file attribute byte  }
  133.  
  134.         { If error occured set, Return code. }
  135.  
  136.         Carry_flag := 1 and Flags;      { If Carry flag, error occured }
  137.                                         { and Ax will contain Return code }
  138.         if Carry_flag = 1 then
  139.           begin
  140.           RetCode_code := Ax and $00FF;
  141.           end
  142.  
  143.         else
  144.           begin
  145.           RetCode_code := 0;
  146.           Filename := '             ';
  147.           for N := 0 to 12 do FileName[N+1] := Buffer.Name[N];
  148.         s1 := lo(buffer.filesizelo);
  149.         s2 := hi(buffer.filesizelo);
  150.         s3 := lo(buffer.filesizehi);
  151.         s4 := hi(buffer.filesizehi);
  152.           end;
  153.  
  154.       end;  {with}
  155. end;
  156. var
  157.   attribyte,
  158.   OldAttribute : byte;
  159.  
  160. {----------------------------------------------------------------------------}
  161. begin
  162.      if paramcount = 0 then filename := '*.*';
  163.      if paramcount > 0 then filename := paramstr(1);
  164.  
  165.      attribyte := 255 ;
  166.      OldAttribute := attribyte;
  167.  
  168.           Find_First(attribyte,filename,Retcode);
  169.               If Retcode = 0 then
  170.                  begin
  171.                      fsize := fsize + (s1 +(s2*256))+65535.0 *(s3 +(s4*256));
  172.                  end;
  173.           {Now we repeat Find_Next until an error occurs }
  174.  
  175.               repeat
  176.                 Find_Next(attribyte,filename,Retcode);
  177.                 if Retcode = 0 then
  178.                  begin
  179.                      fsize := fsize + (s1 +(s2*256))+65535.0 *(s3 +(s4*256));
  180.                  end;
  181.                until Retcode <> 0;
  182. end;
  183.  
  184. {-----------------------------------------------------------------------------}
  185. {        D   E  M  O                                                          }
  186. {-----------------------------------------------------------------------------}
  187. Procedure howmuch ;                   { Give Demonstration of Code               }
  188.  
  189. begin
  190.      fsize := 0.0;
  191.      Get_file;
  192.      writeln(fsize:9:0);
  193. end; { Demo }
  194. begin
  195.  howmuch;
  196. end.
  197.  
  198. Press <CR> to continue: