#!/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:\Perl'; 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 %names = map {chomp;} <$ih>; close $ih; 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 (! $names{$file}) { print $oh_new "$file\n"; } } close $oh_tot; close $oh_new;