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!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.