S
schms
Hi
I have to write a perl program which finds all files in a directory
with mtime (modification time)
of "today - 8 days" ( e.g. today is: 27.7.06, -8 days is: 19.7.06, so
the file's modification
time should be 19.7.06)) and which end on *.ds.
As I am not expert in terms of perl, I found only the following poor
solution.
I was wondering, if anyone has a smarter solution:
use strict;
use File::Find;
use Time::Local;
use Date::Calc qw(Add_Delta_Days Today);
my $DIR = '/aaaaa/bbbb/ccccc';
my $DAYS = 8;
###
### get today
###
my ($YEAR, $MONTH, $DAY) = Today();
###
### get past date
###
my ($PYEAR, $PMONTH, $PDAY) = Add_Delta_Days($YEAR, $MONTH, $DAY,
-$DAYS );
my $epoche_pastdate_start = timelocal(0, 0, 0, $PDAY, $PMONTH-1,
$PYEAR-1900);
my $epoche_pastdate_end = timelocal(59, 59, 23, $PDAY, $PMONTH-1,
$PYEAR-1900);
find (\&my_func, $DIR);
sub my_func {
return unless -f;
return unless ( $File::Find::name =~ /.ds$/ );
my $epoche_mtime = (stat($File::Find::name))[9];
if ( $epoche_mtime >= $epoche_pastdate_start && $epoche_mtime
<= $epoche_pastdate_end ) {
system("ls -al $File::Find::name");
}
I thank you for your comments.
Stefan
I have to write a perl program which finds all files in a directory
with mtime (modification time)
of "today - 8 days" ( e.g. today is: 27.7.06, -8 days is: 19.7.06, so
the file's modification
time should be 19.7.06)) and which end on *.ds.
As I am not expert in terms of perl, I found only the following poor
solution.
I was wondering, if anyone has a smarter solution:
use strict;
use File::Find;
use Time::Local;
use Date::Calc qw(Add_Delta_Days Today);
my $DIR = '/aaaaa/bbbb/ccccc';
my $DAYS = 8;
###
### get today
###
my ($YEAR, $MONTH, $DAY) = Today();
###
### get past date
###
my ($PYEAR, $PMONTH, $PDAY) = Add_Delta_Days($YEAR, $MONTH, $DAY,
-$DAYS );
my $epoche_pastdate_start = timelocal(0, 0, 0, $PDAY, $PMONTH-1,
$PYEAR-1900);
my $epoche_pastdate_end = timelocal(59, 59, 23, $PDAY, $PMONTH-1,
$PYEAR-1900);
find (\&my_func, $DIR);
sub my_func {
return unless -f;
return unless ( $File::Find::name =~ /.ds$/ );
my $epoche_mtime = (stat($File::Find::name))[9];
if ( $epoche_mtime >= $epoche_pastdate_start && $epoche_mtime
<= $epoche_pastdate_end ) {
system("ls -al $File::Find::name");
}
I thank you for your comments.
Stefan