http://www.perlmonks.org?node_id=932647


in reply to Delete Old Directories

Hello, this is what I would do. Please see comments

#!/usr/bin/perl use strict; my $older_than = 45; # my @dirs = #could be this depending then just foreach them my @files = </Users/somedir/*>; foreach my $filename (@files) { next unless (-d $filename); # this is only letting dirs get past if ( int( -M $filename) > $older_than) { #do something print"dir is old:$filename\n";#print what is deleted here. # test what you are going to delete #&erase_directory ($filename); # after test uncomment this #rmdir $filename; # after test uncommnet this } } sub erase_directory { my $directory = shift @_; my @files = <$directory/*>; foreach (@files){ unlink "$_"; } }

good luck, Rob