SamQi has asked for the wisdom of the Perl Monks concerning the following question:
Well, I finally figured out a way to take care of my file recursion problem with File::Find...however...
When I run the code, it goes into every directory *BUT* the one I want it to. I'm sure the solution is going to make me feel dense...but here's the code:
#### rerurseDir
# Description:
# This implements the logical recursion that we use to
# cheat the order find() imposes;
# Params:
# $initPath -> The path to start in.
####
sub recurseDir
{
my $initPath = shift;
my @symlinks;
my @dirs = File::PathConvert::rel2abs($initPath);
my @tempLink;
my @tempDir;
while ( @symlinks or @dirs )
{
if(@symlinks)
{
my ($L, $D) = callFind(@symlinks);
@tempLink = (@tempLink, @{$L});
@tempDir = (@tempDir, @{$D});
}
if(@dirs)
{
my ($L, $D) = callFind(@dirs);
@tempLink = (@tempLink, @{$L});
@tempDir = (@tempDir, @{$D});
}
@symlinks = @tempLink;
@dirs = @tempDir;
@tempLink = @tempDir = ();
}
}
#### callFind
# Description:
# A wrapper for find();
# Params:
# @work -> The array of directories to call find on.
# Returns:
# \@returnLink -> A reference to an array with paths to links in it
# \@returnDir -> The same but with normal dirs instead of links
####
sub callFind()
{
my @work = @_;
my @returnLink;
my @returnDir;
foreach my $entry (@work)
{
find( sub
{
return if ( $_ eq '.' || $_ eq '..');
#my $path = abs_path($File::Find::dir);
if( -d $_ && !-l $_ )
{
$File::Find::prune = 1;
push @returnDir, File::PathConvert::rel2abs($_) unless ( $_ eq "www" or $_ eq "perl" or $_ eq "lost+found" );
}
elsif( -l $_ && -d $_ && $_ =~ /^bin$/ or /^current$/)
{
push @returnLink, File::PathConvert::rel2abs($_)
}
else
{
parseFile(File::PathConvert::rel2abs($_)) unless ($_ =~ /bak$/);
}
} , $entry );
}
return \@returnLink, \@returnDir;
}
Well, that's the portion that is relevant. parseFile() is a subroutine that works (it just basic pattern matching).
parseFile also has the check to see if it is a text file before parsing.
Given this directory structure:
myprojectdir
\
|-> bin -> bin_1.7
|
|-> bin_1.1
|
|-> bin_1.2
:
|-> bin_1.7
The above code evaluates bin_1.1 thru bin_1.6 (hidden by the ..) but IGNORES bin_1.7.
The desired outcome is exactly the opposite: evaluate bin_1.7, but ignore the rest.
Help?
Thanks,
Sam
- Comment on It does exactly the opposite of what I want it to!
| Replies are listed 'Best First'. | |
|---|---|
|
Re: It does exactly the opposite of what I want it to!
by merlyn (Sage) on Sep 22, 2000 at 20:57 UTC | |
by merlyn (Sage) on Sep 22, 2000 at 21:52 UTC | |
by SamQi (Beadle) on Sep 22, 2000 at 22:19 UTC | |
|
Re: It does exactly the opposite of what I want it to!
by isotope (Deacon) on Sep 22, 2000 at 19:57 UTC |