From:	CSBVAX::MRGATE!info-vax-RELAY@KL.SRI.COM@SMTP  8-JUL-1988 13:44
To:	ARISIA::EVERHART
Subj:	Re: file size (a program in VAX Pascal to find it)


Received: from ucbvax.Berkeley.EDU by KL.SRI.COM with TCP; Mon, 4 Jul 88 20:33:31 PDT
Received: by ucbvax.Berkeley.EDU (5.59/1.28)
	id AA27394; Mon, 4 Jul 88 17:00:34 PDT
Received: from USENET by ucbvax.Berkeley.EDU with netnews
	for info-vax@kl.sri.com (info-vax@kl.sri.com)
	(contact usenet@ucbvax.Berkeley.EDU if you have questions)
Date: 4 Jul 88 17:18:41 GMT
From: mandrill!musky2!terrell@tut.cis.ohio-state.edu  (Roger Terrell)
Organization: Muskingum College, New Concord, OH
Subject: Re: file size (a program in VAX Pascal to find it)
Message-Id: <115@musky2.MUSKINGUM.EDU>
References: <8807031818.AA08285@ucbvax.Berkeley.EDU>
Sender: info-vax-request@kl.sri.com
To: info-vax@kl.sri.com

{}

herman%nrl.DECnet@NRL3.ARPA ("NRL::HERMAN") writes:

>	I want to be able to determine the size of a file from within 
>a program without having to do a spawn.  Does anybody have any ideas?

Open the file and read the FAB$L_ALQ (Allocation quantity) field from 
the FAB (File Access Block).  In a file that already exists, this field
will hold the number of blocks allocated to the file.

The method of doing this will, of course, be different from
various languages.  Here is a program in VAX Pascal that does
what you want:

========================================================================

[INHERIT('SYS$LIBRARY:STARLET')]
PROGRAM GetFileSize (INPUT, OUTPUT, InFile);

TYPE
  Unsafe_File = [UNSAFE] FILE OF CHAR;
  FABPtr      = ^FAB$TYPE;
  String      = PACKED ARRAY [1..50] OF CHAR;


FUNCTION PAS$FAB (VAR F : Unsafe_File) : FABPtr; EXTERN;

  
VAR
  InFile     : TEXT;
  InFAB      : FABPtr;
  InFileName : String;
  FileSize   : UNSIGNED;

BEGIN
  WRITELN ('This program finds the size of a "normal" text file.');
  WRITELN ('Note that it will blow up if used to find the size');
  WRITELN ('of other kinds of files, because there is no way');
  WRITELN ('to know in advance what the record length of the file is.');
  WRITELN;
  WRITE ('Enter the name of the file to check: ');
  READLN (InFileName);

  OPEN (InFile, InFileName, OLD, ERROR := CONTINUE);

  IF STATUS(InFile) = 0 THEN
    BEGIN
      InFAB := PAS$FAB (InFile);

      FileSize := InFAB^.FAB$L_ALQ;

      WRITELN;
      WRITELN ('This file is allocated ', FileSize:1, ' Blocks.');
     
      CLOSE (InFile);
    END (* IF *)
  ELSE
    WRITELN ('Error opening file ', InFileName);
END.

=============================================================================

Hope this helps.

--Roger

-- 

Roger Terrell
....musky2!terrell (UUCP) 
terrell@muskingum.edu (CSNet)
