Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^2: Compare dates help!

by Anonymous Monk
on Oct 21, 2011 at 10:46 UTC ( [id://932866]=note: print w/replies, xml ) Need Help??


in reply to Re: Compare dates help!
in thread Compare dates help!

What about this, and that's right, that's how we all learn, let me know:
#!/usr/bin/perl -w use strict; use POSIX qw(strftime); use Date::Calc qw( Today Add_Delta_Days); # get todays date::: my $file_date = sprintf "%04d/%02d/%02d", Today(); my $current_dir = "alldir"; my $exp_dir_date = sprintf "%04d/%02d/%02d",Add_Delta_Days( Today(), - +45 ); print "\n45 Days ago:::$exp_dir_date\n"; my $dir_name = strftime("%Y%m%d",localtime(time)); # when this runs, it will create a new dir in alldir directory. unless(-e $current_dir."/".$dir_name or mkdir ($current_dir."/".$dir_n +ame, 0755)) { die "Unable to create $current_dir."/".$dir_name\n"; } #now open $current_dir and read its content deleting any directory old +er than 45 days opendir (DIR, $current_dir) or die "Couldn't open directory, $!"; while (my $file = readdir DIR) { next if $file=~/^\./; $file =~ s/(\d{4})(\d{2})(\d{2})/$1\/$2\/$3/; if($file lt $exp_dir_date){ $file =~ s/(\d{4})\/(\d{2})\/(\d{2})/$1$2$3/; print "\nDELETE:::$file - $file_date - $exp_dir_date\n\n"; rmdir("alldir/$file"); #-------> remove directory }else{ print "\nOK:::$file* = $file_date - $exp_dir_date\n\n"; } } closedir DIR; print "\n\ndone\n";

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://932866]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-04-25 14:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found