# open the directory for reading chdir "/opt/web/hr83tst/reports"; opendir(REP, "/opt/web/hr83tst/reports") || die "Cannot open the directory /opt/web/hr83/reports $! "; open(remlog,">/Scripts/dir-removed.log"); # open a file to keep as a log of directories removed. print remlog "Directories removed this date : ",`date`, "\n"; # list the contents of the directory. These should be directories. while ($name = readdir(REP)) { if (-M $name >= 10) { print "$name\n" unless($name eq "images"); print remlog "$name\n" unless($name eq "images"); `rm -r $name` unless($name eq "images"); # THIS WILL REMOVE THE DIRECTORY AND ALL OF ITS subdirectories and Files. } } close remlog; closedir(REP)