Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
#!/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;
|
|---|
| 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 |