#!/usr/bin/perl use strict; use warnings; # emailsent.txt-will contain the name of all files for whom an alert has been sent # emailtogo.txt-will contain the name of all new files for whom an alert has to be sent my $matchfile = 'emailsent.txt'; my $outfile = 'emailtogo.txt'; ########################## my $directory = 'C:\'; opendir(DIR, $directory); my @files = grep { $_ ne '.' && $_ ne '..' } readdir DIR; closedir(DIR); # storing all file names in the folder in an array foreach(@files){ print $_,"\n"; } # Build list of old files for comparison open my $ih, '<', $matchfile or die "Can't open file, $matchfile: $!"; my %oldFiles = map {chomp; $_ => 1} <$ih>; close $ih; # Append new files to total list open my $oh_tot, '>>', $matchfile or die "Can't open file, $matchfile: $!"; open my $oh_new, '>', $outfile or die "Can't open file, $outfile: $!"; # Comparing the array to the names in $matchfile foreach my $file (@files) { if (! $oldFiles{$file}) { print $oh_tot "$file\n"; print $oh_new "$file\n"; } } close $oh_tot; close $oh_new;