mbertel has asked for the wisdom of the Perl Monks concerning the following question:

Good day, I am looking for PERL code that will give me all the files that were created before a certain date. Example: Give me all the files that were created before Jan 1, 2006. I would like run this code against my server that I map to. The files I would like the date information is on the server not my pc. Thank you for your assistance. Regards Markus

Replies are listed 'Best First'.
Re: server date script
by siva kumar (Pilgrim) on Jan 09, 2008 at 13:10 UTC
    Try this ... If you want to find files older than 30 days.

    use Data::Dumper; my @list=`find . -type f -mtime +30`; print Dumper \@list;

    The above code will list out all the files older than 30 days.
    You can specify the directory name as  @list=`find /home/abc/dir1/dir2/ -type f -mtime +30`;
Re: server date script
by poolpi (Hermit) on Jan 10, 2008 at 10:01 UTC
    A perlish solution :
    #!/usr/bin/perl use strict; use warnings; use File::Find; use File::stat; use DateTime; use Time::localtime; use Data::Dumper; my %old_file; my ( $dt1, $dt2 ); my ( $tm, $dur, $st); $dt1 = new DateTime( year => 2006, month => 1, day => 1 ); find( \&wanted, '/home/user' ); sub wanted { if ( /[.] pl \z/x ) { $st = stat( $File::Find::name ) or die "No file: $!"; $tm = localtime( $st->mtime ); $dt2 = new DateTime( year => $tm->year + 1900, month => $tm->mon + 1, day => $tm->mday ); $dur = $dt1->subtract_datetime($dt2); $old_file{$_} = $dt2->ymd if $dur->is_positive; } } print Dumper( \%old_file );

    HTH,
    PooLpi
Re: server date script
by hipowls (Curate) on Jan 09, 2008 at 12:13 UTC

    Perl the language is spelt "Perl", perl the executable is spelt "perl", PERL is just shouting.

    Read find2perl

    Update My apologies for being rude, I'd injured my foot & was in some pain. Still that's no excuse and I'll try to be better behaved in the future;).