🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.mac
Article #27007

Re: how to get file size (in bytes) ???

#27007
From: Justin Chris Vallon
Date: Tue, 05 Apr 1988 08:23
38 lines
1612 bytes
(Glen, sorry I couldn't send directly, but UUCP & I don't interface :-)

There are two ways to get the size of a Mac file:

(1)
Remember that a Macintosh file consists of two forks: your code (using
"high-level" calls) should look like:
    FSOpen(fileName, volRefNum, &refNum);
    GetEOF(refNum, &dataForkSize);
    FSClose(refNum);
    OpenRF(fileName, volRefNum, &refNum);
    GetEOF(refNum, &rsrcForkSize);
    FSClose(refNum);
    fileSize = dataForkSize + rsrcForkSize;
This is easy, but it requires that you open the file twice :-(.

(2)
Use "low-level" routines.  Now, you have to create a parameter block, but
you can get the information using one ($1, %1, 01, 1.0, exp(0), 1e+0) calls:

    ParamBlkRec paramBlock

    paramBlock.ioNamePtr = fileName;
    paramBlock.ioVRefNum = volRefNum;
    paramBlock.ioFVersNum = 0; /* must be 0 under finder & HFS */
    paramBlock.ioFDirIndex = 0; /* 0 means don't index, just get info */

    PBGetFInfo(&paramBlock, 0); /* returns an OsErr */

    fileSize = paramBlock.ioFlLgLen + paramBlock.ioFlRLgLen;

----

Both routines will give you the same result, but the second one is a whole
lot better (1 direct call vs 6 round-about calls)...

-Justin
Technical Details
Message-ID: <EWK9ZYy00W0E9Ms0AR@andrew.cmu.edu>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!husc6!bbn!rochester!PT.CS.CMU.EDU!andrew.cmu.edu!jv0l+

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!husc6!bbn!rochester!PT.CS.CMU.EDU!andrew.cmu.edu!jv0l+
From: jv0l+@andrew.cmu.edu (Justin Chris Vallon)
Newsgroups: comp.sys.mac
Subject: Re: how to get file size (in bytes) ???
Message-ID: <EWK9ZYy00W0E9Ms0AR@andrew.cmu.edu>
Date: 5 Apr 88 08:23:00 GMT
Organization: Carnegie Mellon University
Lines: 37
In-Reply-To: <3774@adobe.COM>