Hi Monks!
I have a list of directories named as
11012014
11132014
10092014
09092014
11112015
01012015
04012015
01042011
10122014
I am trying to delete if they are older than 60 days based on their names, but not getting any luck the way I am trying.
...
use File::Path qw( rmtree );
use Date::Simple ('date', 'today');
...
my $dir = '/dir/';
opendir (DIR, $dir) or die "Couldn't open $dir directory, $!";
while (my $directories = readdir DIR) {
next if $directories=~/^\./;
my $dir_found = $directories;
$dir_found =~s/(\d{2})(\d{2})(\d{4})/$3-$1-$2/;
# Difference in days between the dates:
if (date($dir_found) - date($months_ago);
if($days_diff >= 60){
rmtree("$dir/$directories")|| die ("ERROR:::cant delete: $!")
+;
}
}
closedir DIR;
Is there a better way of doing this?
Thanks for looking!