Path: utzoo!attcan!uunet!husc6!bloom-beacon!tut.cis.ohio-state.edu!mandrill!musky2!terrell From: terrell@musky2.MUSKINGUM.EDU (Roger Terrell) Newsgroups: comp.os.vms Subject: Re: file size (a program in VAX Pascal to find it) Keywords: file size, source, pascal Message-ID: <115@musky2.MUSKINGUM.EDU> Date: 4 Jul 88 17:18:41 GMT References: <8807031818.AA08285@ucbvax.Berkeley.EDU> Reply-To: terrell@musky2.MUSKINGUM.EDU (Roger Terrell) Organization: Muskingum College, New Concord, OH Lines: 72 {} 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)