Set $File::Find::prune = 1 before you return for a sub-directory tree you wish to skip.
DWIM is Perl's answer to Gödel
| [reply] [d/l] |
Im not sure exactly what you mean by that, at what point should i set $File::Find::prune = 1?
this is what i have:
find(\&edits, $dir);
sub edits
{
push @$cont, $File::Find::name, stat($File::Find::name) if (!($File::Find::name =~ /.snapshot/));
}
| [reply] |
find(\&edits, $dir);
sub edits {
if ($should_prune)
{
$File::Find::prune = 1
return;
}
push @$cont, $File::Find::name, stat($File::Find::name)
if (!($File::Find::name =~ /.snapshot/));
}
DWIM is Perl's answer to Gödel
| [reply] [d/l] |
find (sub {
#skip directories which begin with 1
if (-d && $_ =~ /^1.*$/) {
$File::Find::prune = 1;
return;
}
#do more stuff here
..........
............
..........
}
I'm not really a human, but I play one on earth.
flash japh
| [reply] [d/l] |
Look at the preprocess option in the documentation.
The code can be used to sort the file/directory names alphabetically, numerically, or to filter out directory entries based on their name alone.
You can pre-process a directory and remove entries for backup directories based on a regex or lookup. File::Find will only follow and process the list of files/directories that are returned by this method.
The example below prints out all files and directories that start with A-D.
#! /usr/bin/perl
use strict;
use warnings;
use File::Find;
find ({wanted => \&wanted, preprocess=> \&preproc, no_chdir=>1}, @ARGV
+);
sub wanted {
print "wanted $_\n"
}
sub preproc {
# print "Pre processing $_\n" foreach (@_);
return grep {/^[A-Da-d]/}@_;
}
| [reply] [d/l] |
This approach also has the advantage, that it works with bydepth, while prune does not.
| [reply] [d/l] [select] |
Hi,
a short
find2perl . -type f spits out the following:
sub wanted {
my ($dev,$ino,$mode,$nlink,$uid,$gid);
(($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
-f _
&& print("$name\n");
}
Regards,
svenXY
Update: Thoroughly reading the OP after I was downvoted (sorry!), I found that the OP only wants to skip certain directories. What I initially wanted to point out is that using the find2perl utility that comes with find2perl spits out nice perl code and can be used to check if the find sub would actually deliver the correct items.. A correct find2perl line for your problem would then be
find2perl . -type d -name "1*" -prune -o -type f -print
, which would spit out:
...
sub wanted {
my ($dev,$ino,$mode,$nlink,$uid,$gid);
(($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
-d _ &&
/^1.*\z/s &&
($File::Find::prune = 1)
||
-f _ &&
print("$name\n");
}
I just wanted to point out how useful this find2perl can be especially the first couple of times.
| [reply] [d/l] [select] |
Am i close with this:
find (sub{
#skip directories which begin with 1
if (-d && $_ =~ /^\.snapshot.*$/)
{
$File::Find::prune = 1;
return;
}
edits => \&edits
},$dir);
| [reply] |
It would help others if you showed the important search settings you used as well as the results. Super Search is powerfull, but can generate a lot of noise.
A useful trick is to set the "Don't include replies" option for a first pass. The search is a lot quicker and less noisy!
DWIM is Perl's answer to Gödel
| [reply] |
| [reply] |