Link to home
Start Free TrialLog in
Avatar of blattamax
blattamax

asked on

use File::Find::Node

I have to use the perl module File::Find::Node in a script which have to do the code in attach

find /files  -type f -mtime +10 | grep -v "/storico/" | grep -v "error" | grep -v "body_email" | grep -v "/in/" | grep -v "/out/" | grep -v "/appoggio/" | grep -v "/responsi_doppi/" | grep -v .sh$| grep -v .pl$

Open in new window

Avatar of Adam314
Adam314


use File::Find::Node;
 
sub found {
    my $node = shift;
    print $node->path . "\n";
}
 
my $f = File::Find::Node->new('/files');
$f->filter(
  sub {
  grep {
        -f $_ 
    and -M _ > 10
    and !m|/storico/|
    and !/error/
    and !/body_email/
    and !m|/in/|
    and !m|/out/|
    and !m|/appoggio/|
    and !m|/responsi_dopi/|
    and !/\.sh$/
    and !/\.pl$/}
    @_}
  );
$f->find;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Todd Mummert
Todd Mummert

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
sorry..that was my browser not giving me scroll bars

Avatar of blattamax

ASKER

this is the find command
find /files  -type f -mtime +10 | grep -v "/storico/" | grep -v "error" | grep -v "body_email" | grep -v "/in/" | grep -v "/out/" | grep -v "/appoggio/" | grep -v "/responsi_doppi/" | grep -v .sh$| grep -v .pl$
The code I posted handles the find and all of the grep parts.  It will run faster than the code without the filter (which filters the results), because directories that are filtered out will not be searched.  The results are printed to the screen.  If you'd like the results somewhere else, let me know.
thank u Adam , if i'd have to remove the results?
>> if i'd have to remove the results?
Meaning, you want to delete the files?  If so, you can update the found subroutine to delete the files.
sub found {
    my $node = shift;
    my $p=$node->path;
    print "$p\n";   #Remove this line if you don't want to print the names of files
    unlink($p) or warn "Could not remove '$p': $!\n";
}

Open in new window