home *** CD-ROM | disk | FTP | other *** search
/ Phoenix CD 2.0 / Phoenix_CD.cdr / 15a / filesize.zip / FILESIZE.PAS
Pascal/Delphi Source File  |  1986-06-10  |  2KB  |  49 lines

  1. PROCEDURE GetFileSize; { ANY SIZE }
  2.  
  3. (*  There  are two  Turbo-Pascal  keywords  for  determining  the size
  4.     of a physical file.  The first, FILESIZE has a built-in limitation
  5.     of being unable to deal with files over 65,536 bytes as it returns
  6.     an integer  value;  the second,  LONGFILESIZE,  makes up  for this
  7.     shortcoming  by  returning a  REAL  value.  Unfortunately, the way
  8.     Turbo handles  REALS  can leave a lot to be desired, and there are
  9.     many times it is  advantageous to  have  integer values with which
  10.     to work.  This  routine  does just that.  As no single integer can
  11.     be assigned a  value of  over 32767,  (nor can ROUND and TRUNC for
  12.     that matter), the array X[] provides the means.
  13.  
  14.     SPECIAL NOTE: Certain keywords (Eg. INT) have been avoided in this
  15.     example, as they do not appear generic in function.        *)
  16.  
  17.  
  18.  
  19. VAR
  20.    Temp      : REAL;
  21.    Oversize  : BOOLEAN;
  22.    I,Q       : INTEGER;
  23.    X         : ARRAY[1..10] OF INTEGER;
  24.    BFILE     : FILE OF BYTE; { MUST be bin file type even if file }
  25.                              { assigned is text.                  }
  26.  
  27. BEGIN
  28.           Q := 1;                        {initialize array}
  29.           FOR I := 0 TO 9 DO             {this will hold sizes <= 327K}
  30.            X[I] := 0;
  31.  
  32.           Assign(BFile,FILEVAR);
  33.           Reset(BFile);
  34.           Temp := LongFileSize(BFile);
  35.             REPEAT
  36.               Oversize := (Temp > 3.2767E+04);
  37.               IF Oversize THEN
  38.               BEGIN
  39.                    Temp := Temp - 3.2767E+04;
  40.                    X[Q] := 32767;        {save excess}
  41.                    Q := Q + 1;
  42.                   END;
  43.             UNTIL NOT Oversize;
  44.             Close(BFile);
  45.           X[0] := Round(Temp);           {now safe to pass to Round}
  46.  
  47.           (* EXACT filesize is now contained in array X[0..Pred(Q)].
  48.              DO NOT try to total these values, use them sequentially. *)
  49. END;