Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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.11012014 11132014 10092014 09092014 11112015 01012015 04012015 01042011 10122014
Is there a better way of doing this?... 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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Delete directories older than 60 days
by toolic (Bishop) on Nov 14, 2014 at 20:13 UTC | |
by Anonymous Monk on Nov 14, 2014 at 20:53 UTC | |
by toolic (Bishop) on Nov 14, 2014 at 21:36 UTC | |
by poj (Abbot) on Nov 14, 2014 at 21:22 UTC | |
|
Re: Delete directories older than 60 days
by Laurent_R (Canon) on Nov 14, 2014 at 19:43 UTC | |
by Anonymous Monk on Nov 14, 2014 at 19:49 UTC | |
|
Re: Delete directories older than 60 days
by RonW (Parson) on Nov 14, 2014 at 22:09 UTC | |
|
Re: Delete directories older than 60 days
by Anonymous Monk on Nov 14, 2014 at 19:50 UTC | |
by Anonymous Monk on Nov 14, 2014 at 20:02 UTC |