protoplasm wrote:
On Oct 23, 2:09 am, [EMAIL PROTECTED] (John W. Krahn) wrote:
Perhaps you need to use the -xdev switch for find to ignore other file
systems?

Thank you, John. That certainly helped. It now ignores the mounted
file systems but still traverses hidden directories. I must be
overlooking something simple. Here is the code and the output:

#!/usr/bin/env perl

use File::Find();

eval("use File::HomeDir;");
die "[err] File::HomeDir not installed. Use \"perl -e \"use CPAN;
install File::HomeDir;\"\" to install \n" if $@;

use strict;
use warnings;
no warnings 'File::Find';
use 5.010;

my $home_directory  = File::HomeDir->my_home;

use vars qw/*name *dir *prune/;
*name  = *File::Find::name;
*dir   = *File::Find::dir;
*prune = *File::Find::prune;

find_directories();
exit;

sub find_directories {
        print "\nLocating directory...\n";
        File::Find::find(\&want_directory, $home_directory);
}

sub want_directory {
        my ($dev,$ino,$mode,$nlink,$uid,$gid);

    (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
    !($File::Find::prune |= ($dev != $File::Find::topdev)) &&
    (
                ! /^\..*\z/si &&
                /^AesTest.*\z/s
    ) &&
    print("$name\n");

}


Output:

Locating directory...
/home/sprotsman/workspace-20080919/AesTest-1.5.6
/home/sprotsman/20081017/workspace/.metadata/.plugins/
org.eclipse.cdt.core/AesTest.1184703311580.pdom
/home/sprotsman/20081017/workspace/.metadata/.plugins/
org.eclipse.cdt.make.core/AesTest.sc
/home/sprotsman/20081017/workspace/AesTest-1.5.7
/home/sprotsman/workspace/AesTest-1.5.2
/home/sprotsman/workspace/AesTest-1.5
/home/sprotsman/workspace/AesTest-1.5.3
/home/sprotsman/workspace/AesTest-1.5.4
/home/sprotsman/workspace/AesTest-1.5.1
/home/sprotsman/workspace/AesTest-1.5.7

I couldn't get $File::Find::prune to work on my system but this may be close to what you require:

#!/usr/bin/perl
use warnings;
use strict;
use File::Find;

eval "use File::HomeDir;";
$@ and die qq{[err] File::HomeDir not installed. Use "perl -e "use CPAN;
install File::HomeDir;"" to install \n};
my $home_directory = File::HomeDir->my_home;

find( sub {
    my $dev = ( lstat )[ 0 ];
    $dev != $File::Find::topdev || $File::Find::name =~ m!/\.! && return;
    /^AesTest/ && print "$File::Find::name\n";
    }, $home_directory );

__END__



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to