#!/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_name, 0755)) { die "Unable to create $current_dir."/".$dir_name\n"; } print "\n"; #now open $current_dir and read its content deleting any directory older 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;