[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Getting size of resource forks



At 13:36 4/28/96, Bill Middleton wrote:
>If you can use the new PowerTools extensions, try something like
>this:
>
>use Mac::Resources;
>$prev = CurResFile();
>$res = OpenResFile("UNIX:Mac_Perl_510r2_a1:MiniPerl.68k") || die "$^E";
>UseResFile($res);
>print "Types: ", Count1Types(), "\n\n";
>for ($types = Count1Types()+1; $types; --$types) {
>        $type = Get1IndType($types);
>        print "Resources of type $type: ", Count1Resources($type), "\n";
>        for ($rsrcs = Count1Resources($type); $rsrcs; --$rsrcs) {
>                $rsrc = Get1IndResource($type, $rsrcs);
>                $size = GetResourceSizeOnDisk($rsrc);
>                $total += $size;
>        }
>}
>print "Total size of all resources = $total\n";
>UseResFile($prev);
>CloseResFile($res);
>
>
>Hopefully faster than asking the finder.

And produces a smaller number in any file whose resource fork hasn't been
compacted <and smaller by the per file, per type and per resource overhead
and the sizes of the names of the named resources, probably, too>.  Which
number is wanted (bytes in resource fork vs total bytes in the active
resources data) is unclear, but more likely it's the former, which the
excellent script above doesn't produce.  Aside from the holes, the
overheads are computable, but it hardly seems reasonable to do so.

An XCMD which gets the data from the file system would seem easier (and
it's quicker than firing an AppleScript script at the Finder).  But it's
hard to write for all possible foreign file systems, probably.  There may
well already be one lying around in HyperCard land.

   --John

  --
   Each day is a gift.  That's why we call today "the present."
jwbaxter@olympus.net (John W. Baxter)  Port Ludlow, WA, USA