I am currently using this script in comparing two indentical directories. If a file is removed from one directory, the corresponding file should be removed from the
other directory. Currently the script is listing all the files in the corresponding directory, instead of listing the ones that should be removed. Any help would be greatly appreciated. Thanks in advance.
use File::Find;
use File::Basename;
# Read the contents of the first directory (DOC) into a hash
$first_dir = "c:/data/documents/pdfx/input";
%docs = ();
find (\&firstDir, $first_dir);
sub firstDir {
/.doc/ or return;
-f and ($name,$path,$suffix) = fileparse($File::Find::name);
$docs{$name} = 1;
}
# Now read the contents of the second directory (PDF) into an array
$second_dir = "c:/data/documents/pdfx/output";
@pdfs=();
find (\&secondDir, $second_dir);
sub secondDir {
/.pdf/ or return;
-f and ($name,$path,$suffix) = fileparse($File::Find::name);
push @pdfs, $name;
}
# Now delete the files in the second dir that aren't in the first dir.
foreach $file (@pdfs) {
if (!defined($docs{$file})) {
$delfiles = "${second_dir}/${file}";
print "unlink $delfiles\n";
unlink($delfiles);
}
}