use DirHandle (); use File::Spec (); use strict; use warnings; # Sets basic globals my $now = localtime; my $dir = "C:/Data"; my $dirL = "C:/DataL"; my $fCount=0; my $fCountL=0; # Sorts files in $dir and sets $latest->{file} with newest file. my $latest = (sort {$b->{mtime} <=> $a->{mtime}} map {{mtime => -M $_, file => $_}} <$dir/*>)[-1]; my $newM = (stat $latest->{file})[9]; # Sorts files in $dir and sets $oldest->{file} with oldest file. my $oldest = (sort {$a->{mtime} <=> $b->{mtime}} map {{mtime => -M $_, file => $_}} <$dir/*>)[-1]; my $oldM = (stat $oldest->{file})[9]; # Opens $dir and counts number of files opendir(DIR, $dir); LINE: while(my $FILE = readdir(DIR)) { next LINE if($FILE =~ /^\.\.?/); $fCount++; } closedir(DIR); # Opens $dirL and counts number of files opendir(DIRL, $dirL); LINE: while(my $FILE2 = readdir(DIRL)) { next LINE if($FILE2 =~ /^\.\.?/); $fCountL++; } closedir(DIRL); # Changes Newest/Oldest file display in email based on if any files are found. my $latestF =''; my $oldestF =''; my $noFiles = 'Data: Empty directory, no files found that need to be processed.'; my $noFilesL = 'DataL: Empty directory, no files found that need to be processed.'; if (($latest->{file}) || ($oldest->{file})){ $latestF = 'Newest File: '. $latest->{file}. ' with a timestamp of '. scalar localtime $newM; $oldestF = 'Oldest File: '. $oldest->{file}. ' with a timestamp of '. scalar localtime $oldM; $noFiles = ''; } exit;