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

[MacPerl] Getting size of resource forks



In the process of learning MacPerl by studying Larry Wall's
book, I wrote a recursive program to print a directory listing
with Creator, Type and Size.

I found that applications and resource files return 0 bytes!
How can I get the total size of any file - applications,
resource files, aliases, the Desktop and Icons.

Here is my program

# Recursive Directory Listing    lsr.pl
# Written 28 April 1996
#
require "GUSI.ph" ;

$folderchoice = &MacPerl'Choose(&GUSI'AF_FILE, 0,
        "", "", &GUSI'CHOOSE_DIR);

$level = 1;
$ul = '=' x length($folderchoice);
print "\n\n$folderchoice\n$ul\n";


&listdir($folderchoice, $level);

sub listdir {
 local($cwd, $level) = @_;
 local($indent) = "  " x $level;
 # print "Analysing $cwd at level $level\n";
 chdir($cwd) || die "couldnt change directory\n";
 opendir(THISDIR,$cwd) || die "couldnt open $cwd\n";
 local(@filenames) = readdir(THISDIR);
 closedir(THISDIR);
 local($entry);
 foreach $entry (@filenames) {
    if (-d $cwd.":".$entry) {
       print "$indent$entry (Directory)\n";
       &listdir($cwd.":".$entry, $level+1);
    } else {
       ($fc, $ft) = &MacPerl'GetFileInfo($cwd.":".$entry);
       $fs = (-s $cwd.":".$entry);
       ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
            $atime, $mtime, $ctime,
            $blksize, $blocks) = stat($cwd.":".$entry);
       print "$indent$entry ($fc,$ft) $fs $size $blocks\n";
    }
 }
}

Here are the results:-

MacintoshHD:Games
=================
  Kid Pix  (Kid2,APPL) 0 0 0
  My Stamps (Kid2,Kext) 0 0 0
  PlayRoom (PLRM,APPL) 0 0 0
  PR Resources (Directory)
    ABCBook.rsrc (PLRM,PLR2) 0 0 0
    ABCScene1.rsrc (PLRM,PLR2) 0 0 0
    ABCScene2.rsrc (PLRM,PLR2) 0 0 0
    ABCScene3.rsrc (PLRM,PLR2) 0 0 0
    AllSounds1.rsrc (PLRM,PLR1) 0 0 0
    AllSounds2.rsrc (PLRM,PLR1) 0 0 0
    Computer.rsrc (PLRM,PLR2) 0 0 0
    CuckooClock.rsrc (PLRM,PLR2) 0 0 0
    DiceGames.rsrc (PLRM,PLR2) 0 0 0
    MainPlayRoom.rsrc (PLRM,PLR2) 0 0 0
    MixerToy.rsrc (PLRM,PLR2) 0 0 0
    NumberSpinner.rsrc (PLRM,PLR2) 0 0 0
    Playroom Sound Driver (PLRM,PLR1) 0 0 0
    PR ExtraSounds (TEXT,TEXT) 0 0 0
    PR Scrapbook (PLRM,TEXT) 620 620 1
    PR Settings (PLRM,TEXT) 16 16 1
  Shufflepuck Cafˇ (PUCK,APPL) 24310 24310 10


P.S. I'm not much of a game player, but my daughter liked
Playroom at the age of two, and Tree House at age 4.
My favourite is Shufflepuck Cafe!


Many thanks,
Charles


P.S.  Thanks for all the book suggestions on learning Applescrip.
I chose the cheapest book and probably the most readable,
namely APPLESCRIPT FOR DUMMIES.


------------------------------------------------------
Charles Cave
Sydney, Australia
Email: charles@jolt.mpx.com.au
URL:   http://www.ozemail.com.au/~caveman
------------------------------------------------------