### ------------------------------- ### Read local directory opendir LOCALDIR, $location || croak "Unable to open: $location because $!"; @local_files = readdir LOCALDIR; foreach $file (@local_files){ ### Don't try to delete directories if ($file eq '.' || $file eq '..' || -d "$location$file" ) { next; } ### Test the age of each file in the directory and delete ### if too old (N.B. need to prepend directory to find file and ### use unlink for OS portable deletion). if ( -M "$location$file" <= $age) { $p_debug && print "$file is ok, only ", -M "$location$file", " days old\n"; } else { $p_debug && print "$file is too old, it's ", -M "$location$file", " days old\n"; unlink("$location$file") || croak "Unable to delete: $location$file because: $!"; } } #### ### Move each file into archive directory move( "$location$file", "$target$file") || croak "Unable to move: $location$file because: $!";