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

Re: [MacPerl] Need a Program



At 2:32 PM -0700 6/14/99, Elton Hughes wrote:
>I need two scripts (or one that does two things). I want it to traverse a
>whole hard drive or AppleShare server and then tell me how many documents
>of type 'X' there are.


Just last week I was doing something somewhat similar.
Here's some code I used to get a list of the files I
had patched in my most recent development process:


#!perl

use File::Recurse;

recurse {
    $ws = $_;
    $ws =~ s/:patch:/:/;

    if (-M $_ > -M $ws and ! -d $ws) {print "$ws\n";}

} "Macintosh HD:patch:WebSTAR";

__END__


I found File::Recurse on CPAN.  I had to hack one line in it to
change a "/" to a ":" for mac paths:


sub recurse (&$;$$) {
    my $exe = shift;
    my $dir = shift;
    my $context = shift;
    my $level = shift;
    my $file;
    my $ret = 0;
    local *D;
    local $_;

    $level = 0 unless defined $level;
    return undef if (!-d $dir);
    croak("Recursion ran too deep on $dir")
      if $level > $File::Recurse::MAX_DEPTH;
    opendir(D,$dir) || return horf($dir);
    while(defined($file = readdir D)) {
	next if ($file eq '.' || $file eq '..');
	my $path = "$dir:$file";  ################# my $path = "$dir/$file"
	next unless -e $path;

	$_ = $path;
	$ret = &$exe($path,$context);
	next if ($ret == -1);
	last if ($ret == -2);

	if (-d _) {
	    next if (-l $path && !$File::Recurse::FOLLOW_SYMLINKS);
	    $ret = recurse($exe,$path,$context,$level+1);
	    last if ($ret == -2);
	}
    }
    closedir D;

    return $ret;
}

__END__

If you've been paying any attention to the often repeated discussion
about mac path conventions vs. $otherOS path conventions you will
likely recognize that the original code isn't particularly thoughtful
about paths or other platforms.  My hack is consistent with the spirit
of the original code in this regard  8^).

I haven't made any attempts to pass this info along to the original
author, nor to CPAN testers, nor ... well anyone until now.
Appologies for my False Laziness.

There may be better ways to do it.
-Eric



===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org