[comp.os.vms] file size

gtchen@faline.bellcore.com (George T. Chen) (08/05/87)

Does anyone know of a way to get a file size on a vms system when
not in the os?  For example, if I'm running fortran.  I've been
told there is a way to get the maximum record allowed for
direct files but what if the file has variable length records.
When I do a DIR/FULL the size will respond with N/M where N
is the current number of blocks used and M is the maximum allowed.
I'm trying to get the N if possible.  Any help appreciated.

gtchen@faline.bellcore.com

herman%nrl.DECnet@NRL3.ARPA ("NRL::HERMAN") (06/29/88)

	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?


					Charles Herman
					herman%nrl.decnet@nrl.arpa

carl@CITHEX.CALTECH.EDU (Carl J Lydick) (07/04/88)

 > 	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?

Depends on what language you're using.  From C, you can use stat or fstat
(for more information, type HELP CC RUN FSTAT or HELP CC RUN STAT).  From
most languages, you can do this through calls to RMS, but calling the C
functions will probably be easier.

terrell@musky2.MUSKINGUM.EDU (Roger Terrell) (07/05/88)

{}

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)