home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Phoenix CD 2.0
/
Phoenix_CD.cdr
/
15a
/
filesize.zip
/
FILESIZE.PAS
Wrap
Pascal/Delphi Source File
|
1986-06-10
|
2KB
|
49 lines
PROCEDURE GetFileSize; { ANY SIZE }
(* There are two Turbo-Pascal keywords for determining the size
of a physical file. The first, FILESIZE has a built-in limitation
of being unable to deal with files over 65,536 bytes as it returns
an integer value; the second, LONGFILESIZE, makes up for this
shortcoming by returning a REAL value. Unfortunately, the way
Turbo handles REALS can leave a lot to be desired, and there are
many times it is advantageous to have integer values with which
to work. This routine does just that. As no single integer can
be assigned a value of over 32767, (nor can ROUND and TRUNC for
that matter), the array X[] provides the means.
SPECIAL NOTE: Certain keywords (Eg. INT) have been avoided in this
example, as they do not appear generic in function. *)
VAR
Temp : REAL;
Oversize : BOOLEAN;
I,Q : INTEGER;
X : ARRAY[1..10] OF INTEGER;
BFILE : FILE OF BYTE; { MUST be bin file type even if file }
{ assigned is text. }
BEGIN
Q := 1; {initialize array}
FOR I := 0 TO 9 DO {this will hold sizes <= 327K}
X[I] := 0;
Assign(BFile,FILEVAR);
Reset(BFile);
Temp := LongFileSize(BFile);
REPEAT
Oversize := (Temp > 3.2767E+04);
IF Oversize THEN
BEGIN
Temp := Temp - 3.2767E+04;
X[Q] := 32767; {save excess}
Q := Q + 1;
END;
UNTIL NOT Oversize;
Close(BFile);
X[0] := Round(Temp); {now safe to pass to Round}
(* EXACT filesize is now contained in array X[0..Pred(Q)].
DO NOT try to total these values, use them sequentially. *)
END;