Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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:
Thanks for the Help!
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!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Delete Old Directories
by Marshall (Canon) on Oct 20, 2011 at 02:19 UTC | |
by Anonymous Monk on Oct 20, 2011 at 10:51 UTC | |
by choroba (Cardinal) on Oct 20, 2011 at 12:21 UTC | |
by Marshall (Canon) on Oct 24, 2011 at 06:08 UTC | |
Re: Delete Old Directories
by williams554 (Sexton) on Oct 20, 2011 at 12:53 UTC | |
by Anonymous Monk on Oct 20, 2011 at 22:32 UTC | |
by williams554 (Sexton) on Oct 21, 2011 at 04:47 UTC |
Back to
Seekers of Perl Wisdom