Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Thanks for the help!#!/usr/bin/perl -w use strict; use Date::Calc qw( Today Add_Delta_Days ); my $date = sprintf "%04d/%02d/%02d",Add_Delta_Days( Today(), -30 ); $date =~ s/(\d{4})\/(\d{2})\/(\d{2})/$1$2$3/; print "\n\n Deleting directory(ies) if older than 30 days::: $date \n\ +n\n"; my $dir = "/to_del"; opendir (DIR, $dir) or die "Couldn't open directory, $!"; while (my $f_dir = readdir DIR) { next if $f_dir=~/^\./; next unless (-d "$dir/$f_dir"); # 20111205 - this is the name of the directy(ies) in /to_del directo +ry , they have date for their names if($f_dir le $date){ print "\nDeleted - $f_dir\n\n"; rmdir("$dir/$f_dir") || die ("cant delete: $?"); } } closedir DIR; print "\n\n Done \n\n\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Removing directories with rmdir!
by toolic (Bishop) on Jan 05, 2012 at 20:44 UTC | |
by Anonymous Monk on Jan 05, 2012 at 20:51 UTC | |
by ikegami (Patriarch) on Jan 05, 2012 at 21:01 UTC | |
by Anonymous Monk on Jan 06, 2012 at 02:47 UTC | |
|
Re: Removing directories with rmdir!
by ww (Archbishop) on Jan 05, 2012 at 20:44 UTC |