> -----Original Message-----
> From: [email protected] [mailto:perl-
> [email protected]] On Behalf Of
> [email protected]
> Sent: Friday, December 09, 2011 4:33 PM
> To: [email protected]
> Subject: File::Find::Rule problem
>
> I have a real head scratcher trying to exclude directories with
> File::Find:Rule version 0.32.
>
> I have made a small test directory on my Windows XP machine with the
> following two files:
>
> D:\My Documents\projects\dave\test\log.txt
> D:\My Documents\projects\dave\test\84_33 (Kland, Dan)\test.pl
>
> I want to exclude the Kland directory and just return log.txt (I know I
> can set the depth of the find - this is just an illustrative problem
> for a much larger directory structure).
>
> Here is my test program:
>
> use File::Find::Rule;
> use strict 'vars';
>
> my $rule = new File::Find::Rule ();
> my @exclude = (qr/Kland, Dan/);
> $rule->or(
> $rule->new->directory->name(@exclude)->prune->discard,
> $rule->new
> );
>
> my @files = $rule->file->in('D:\My Documents\projects\dave\test');
>
> foreach my $file (@files) {
> print STDERR "$file\n";
> }
>
> It works as it should, only returning log.txt
>
> However if I make certain changes to the exclude regex it fails (i.e.,
> the program runs fine but returns both files, including test.pl which
> it should not).
>
> This works: my @exclude = (qr/\(Kland, Dan\)/); This works: my @exclude
> = (qr/84_33/); So does this (with a space at the end): my @exclude =
> (qr/84_33 /); This does not: my @exclude = (qr/84_33 \(Kland, Dan\)/);
> This doesn't work either (adding a single space in front): my @exclude
> = (qr/ \(Kland, Dan\)/); And this crashes with a lengthy
> File::Find::Rule compile error: my @exclude = (qr/84_33 \(/);
>
> So, it's not the spaces, it's not the parentheses, it's ... something.
>
> Can anyone see what I'm doing wrong, or at least replicate the problem?
>
> Arvin
>
> This is perl, v5.10.0 built for MSWin32-x86-multi-thread (with 5
> registered patches, see perl -V for more detail)
>
> Copyright 1987-2007, Larry Wall
>
> Binary build 1004 [287188] provided by ActiveState
> http://www.ActiveState.com Built Sep 3 2008 13:16:37
> _______________________________________________
Hello,
I had never used File::Find::Rule before, but I gave it a try.
ActivePerl 5.8.9 Build 826.
I set up a test with 3 files in the directory hierarchy:
D:/My Documents/projects/dave/test/should-print.txt
D:/My Documents/projects/dave/test/84-33 (Kland, Dan)/test.pl
D:/My Documents/projects/dave/test/84-33 Kland, Dan/test2.pl
Then ran the following code:
use strict;
use warnings;
use File::Find::Rule;
my $ctr = 1;
print "\n\n============== START =====================\n";
while (my $pattern = <DATA>)
{
chomp $pattern;
my $rule = new File::Find::Rule ();
my $subctr = 'a';
foreach my $modifiedPattern ( qr/\Q$pattern\E/, $pattern )
{
my @exclude = ($modifiedPattern);
print "\n=============================================\n";
print "== $ctr$subctr >>$exclude[0]<<\n\n";
$rule->or(
$rule->new->directory->name(@exclude)->prune->discard,
$rule->new
);
my @files = $rule->file->in('D:/My Documents/projects/dave/test');
foreach my $file (@files) {
print "$file\n";
}
$subctr++;
}
$ctr++;
}
__DATA__
Kland, Dan
(Kland, Dan)
84-33
84-33
84-33 (Kland, Dan)
84-33 Kland, Dan
84-32
This produced the output listed below
============== START =====================
=============================================
== 1a >>(?-xism:Kland\,\ Dan)<<
D:/My Documents/projects/dave/test/should-print.txt
=============================================
== 1b >>Kland, Dan<<
D:/My Documents/projects/dave/test/should-print.txt
=============================================
== 2a >>(?-xism:\(Kland\,\ Dan\))<<
D:/My Documents/projects/dave/test/should-print.txt
=============================================
== 2b >>(Kland, Dan)<<
D:/My Documents/projects/dave/test/should-print.txt
=============================================
== 3a >>(?-xism:84\-33)<<
D:/My Documents/projects/dave/test/should-print.txt
=============================================
== 3b >>84-33<<
D:/My Documents/projects/dave/test/should-print.txt
=============================================
== 4a >>(?-xism:84\-33\ )<<
D:/My Documents/projects/dave/test/should-print.txt
=============================================
== 4b >>84-33 <<
D:/My Documents/projects/dave/test/should-print.txt
=============================================
== 5a >>(?-xism:84\-33\ \(Kland\,\ Dan\))<<
D:/My Documents/projects/dave/test/should-print.txt
D:/My Documents/projects/dave/test/84-33 (Kland, Dan)/test.pl
D:/My Documents/projects/dave/test/84-33 (Kland, Dan)/test.pl~
=============================================
== 5b >>84-33 (Kland, Dan)<<
D:/My Documents/projects/dave/test/should-print.txt
D:/My Documents/projects/dave/test/84-33 (Kland, Dan)/test.pl
D:/My Documents/projects/dave/test/84-33 (Kland, Dan)/test.pl~
=============================================
== 6a >>(?-xism:84\-33\ Kland\,\ Dan)<<
D:/My Documents/projects/dave/test/should-print.txt
D:/My Documents/projects/dave/test/84-33 (Kland, Dan)/test.pl
D:/My Documents/projects/dave/test/84-33 (Kland, Dan)/test.pl~
=============================================
== 6b >>84-33 Kland, Dan<<
D:/My Documents/projects/dave/test/should-print.txt
D:/My Documents/projects/dave/test/84-33 (Kland, Dan)/test.pl
D:/My Documents/projects/dave/test/84-33 (Kland, Dan)/test.pl~
=============================================
== 7a >>(?-xism:84\-32)<<
D:/My Documents/projects/dave/test/should-print.txt
D:/My Documents/projects/dave/test/84-33 (Kland, Dan)/test.pl
D:/My Documents/projects/dave/test/84-33 (Kland, Dan)/test.pl~
D:/My Documents/projects/dave/test/84-33 Kland, Dan/test2.pl
=============================================
== 7b >>84-32<<
D:/My Documents/projects/dave/test/should-print.txt
D:/My Documents/projects/dave/test/84-33 (Kland, Dan)/test.pl
D:/My Documents/projects/dave/test/84-33 (Kland, Dan)/test.pl~
D:/My Documents/projects/dave/test/84-33 Kland, Dan/test2.pl
===== END OF OUTPUT ======
It appears that the parentheses are being ignored.
The following names, produce the same results.
And, they never seem to eliminate the directory with the parentheses.
== 5a >>(?-xism:84\-33\ \(Kland\,\ Dan\))<<
== 5b >>84-33 (Kland, Dan)<<
== 6a >>(?-xism:84\-33\ Kland\,\ Dan)<<
== 6b >>84-33 Kland, Dan<<
Also, the following should not have excluded the directory "84-33 Kland,
Dan", but it did.
== 2a >>(?-xism:\(Kland\,\ Dan\))<<
So, there does seem to be something amiss.
Ken
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs