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

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


use File::Find::Node;
sub found {
    my $node = shift;
    print $node->path . "\n";
my $f = File::Find::Node->new('/files');
  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$/}

Open in new window

Todd MummertCommented:

first the grep on the end is illegal, since grep has to take an argument...    I don't know what you want there, so I'll ignore it in the script below.

Also, why is using File::Find::Node a requirement?     Well, in any case, it works like this:

#!/usr/bin/perl -w
use strict;
use File::Find::Node;
my $dir = '/files';     # path for find
my $mtime = 10;         # find file before N days ago
my $now = time;
# this isn't strictly correct, since find removes fractional days
my $cutoff = $now-$mtime*24*60*60;
my $f = File::Find::Node->new($dir);
sub proc {
    my $f = shift;
    return if $f->type ne "f";
    return if $f->path =~ m,/storico/|error,;
    return unless $f->mtime < $cutoff;
    print $f->path."\n";

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Todd MummertCommented:
sorry..that was my browser not giving me scroll bars

Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

blattamaxAuthor Commented:
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.
blattamaxAuthor Commented:
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

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.