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

Re: [MacPerl] MAC Filesystem Help



>If you have any aliases to directories, some files will be processed
>more than once. If you have any aliases to directories that are ancestors
>of the alias, the script will run until MacPerl runs out of memory.

Well, yes. But there are actually other problems that are perhaps more 
likely
to occur. There is quite a bit of work to do to make the fragment a usable
script, but here's a version that solves a couple of problems. It won't 
process
a file twice, and it won't abort if it hits a file it can't open (such as 
a
folder icon.) Since the original problem involved a DOS directory, neither
aliases nor folder icons are likely to be an issue. On the other hand, 
the nature
of the files to be processed might require (or permit) other changes as 
well.

#!perl

my %done;
while (@ARGV) {
    my $arg = shift;
    process( $arg );        
}

sub process {
    my $fn = shift;
    return if  $done{$fn}++ or -l $fn and $done{readlink $fn}++;
    if ( -d $fn ) {
        local *D;
        opendir D, "$fn" or die "Couldn't open dir $fn; $!";
        while ( my $file = readdir D ) {
            process( "$fn:$file" ) ;
        }
    } else {
        eval {
            open_f( "$fn" );
        };
        if ( $@ ) {
            if ( $fn =~ /Icon\n$/ ) {
                chop $fn;
                print "*" x length $argnr, ": $fn is an icon.\n";
            } else {
                print $@;
            }
            return;
        }
        print ++$argnr, ": $fn\n"; # or process as you like
        close F; 
    }
}

sub open_f {
    open F, "$_[0]" or die "Couldn't open $_[0]; $!";
}

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch