<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>
Date   : Sun, 20 Jan 1985 21:13:31 PST
From   : bang!crash!ihom@Nosc.ARPA
Subject: Re: File sizes from Turbo

 
>  Does anyone know an easy way to get file sizes in Kilobytes using
>  TurboPascal?  If it would help I have a Kaypro computer.
 
In CP/M-80, the Turbo Pascal "filesize(filvar)" function will return the
number of records in the named file.  Each record consumes 128 bytes.  So,
the Kilobyte size is calculated by:  RECS x 128.  When the file is saved
in CP/M, file space is allocated in increments of 2K bytes.  The following
example will calculate the K's.
 
program find_k;
type
   filename = string[12];
var
   fname : filename;
   kfile : file;
   remain : boolean;
   i,recs,k,bytes : integer;
begin
   write('Enter the filename: ');
   readln(fname);
   for i:=1 to length(fname) do
      fname[i]:=upcase(fname[i]);
   assign(kfile,fname);
   reset(kfile);
   recs:=filesize(kfile);
   close(kfile);
   bytes:=recs*128;          { how many 128 byte records }
   k:=bytes div 1024;          { get the nearest k. oKay? }
   remain:=(bytes mod 1024)<>0;          { do I need another k? }
   if remain then k:=k+1;
   if (k=0) or odd(k) then k:=k+1;     { add another k for CP/M filesaves }
   writeln('That file is ',k,'K long')
end.


--Irwin Hom          {ihnp4, sdcsvax!bang}!crash!ihom
                          bang!crash!ihom@nosc
                               bang!crash!ihom@ucsd
<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>