Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: Searching for files efficiently help!

by Anonymous Monk
on Nov 16, 2011 at 18:24 UTC ( #938434=note: print w/ replies, xml ) Need Help??


in reply to Re: Searching for files efficiently help!
in thread Searching for files efficiently help!

Do you mean something like this?

#!/usr/bin/perl -w use strict; use File::Find::Rule; my $startdir = "/allfiles"; my @filelist = qw(1234567_bc_20101000.txt 99877_xy_20111111.txt); #for +testing my %filelist = map {$_, 1} @filelist; my $includeFiles = File::Find::Rule->file ->name('*.txt'); # search by file extensi +ons my @files = File::Find::Rule->or( $includeFiles ) ->in($startdir); #locate only txt files in the starting directory my $includeFiles = File::Find::Rule->file ->name('*.txt'); # search by file extensi +ons my @files = File::Find::Rule->or( $includeFiles ) ->in($startdir); my $f_name; my $c=0; foreach my $files(@files) { $c++; if($files=~/(.*?)\/([^\/]+)$/) { $f_name = $2; } if (exists $filelist{$f_name}) { print "$c - Found and to be deleted: $files\n"; } }

But when I print the results I am getting all files and not only the ones that was found!
Thanks!


Comment on Re^2: Searching for files efficiently help!
Download Code
Replies are listed 'Best First'.
Re^3: Searching for files efficiently help!
by jethro (Monsignor) on Nov 17, 2011 at 13:15 UTC

    Can't confirm your observation. I tested this script and it worked as expected, after throwing away the duplicate lines "my $includeFiles = ..." and "my @files = ..".

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://938434]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (15)
As of 2015-07-31 20:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (281 votes), past polls