home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol292 / size.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1986-12-22  |  1013 b   |  33 lines

  1. (*
  2. In CP/M-80, the Turbo Pascal "filesize(filvar)" function will return the
  3. number of records in the named file.  Each record consumes 128 bytes.  So,
  4. the Kilobyte size is calculated by:  RECS x 128.  When the file is saved
  5. in CP/M, file space is allocated in increments of 2K bytes.  The following
  6. example will calculate the K's.
  7. *)
  8. program find_k;
  9. type
  10.    filename = string[12];
  11. var
  12.    fname : filename;
  13.    kfile : file;
  14.    remain : boolean;
  15.    i,recs,k,bytes : integer;
  16. begin
  17.    write('Enter the filename: ');
  18.    readln(fname);
  19.    for i:=1 to length(fname) do
  20.       fname[i]:=upcase(fname[i]);
  21.    assign(kfile,fname);
  22.    reset(kfile);
  23.    recs:=filesize(kfile);
  24.    close(kfile);
  25.    bytes:=recs*128;          { how many 128 byte records }
  26.    k:=bytes div 1024;          { get the nearest k. oKay? }
  27.    remain:=(bytes mod 1024)<>0;          { do I need another k? }
  28.    if remain then k:=k+1;
  29.    if (k=0) or odd(k) then k:=k+1;     { add another k for CP/M filesaves }
  30.    writeln('That file is ',k,'K long')
  31. end.
  32.  
  33.