Hi Monks!
I have a program that creates everyday a directory using today's date, I need to read these directories every day and if any is older than 45 days delete it. My question is what would be the best way to delete this directory, using its name of from its age? I only have so far this code to try something:
#!/usr/bin/perl -w
use strict;
use POSIX qw(strftime);
my $current_dir = "/alldir";
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";
}
print "\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=~/^\./;
#unlink if -D $file > 45;
print "$file\n";
}
closedir DIR;
Thanks for the Help!