I’m writing a Perl script to automatically copy PDFs from a folder.
Users are unable to access folders they don’t have permission for so they don’t accidentally gain access to any information they aren’t supposed to.
I have a rough mock-up which works except for one bug: it keeps seeing the . and .. folders and opens them entering infinite loops.
The following conditional statement checked to see the file was a PDF, which would then pass to my copyPDF, which checks for exceptions and then copies the file; otherwise it passes and tries to open as a folder if a folder scans that content and repeats.
I’ve tried a number of ways to ignore the . and .. but it always leads to ignoring all other subfolders as well. Has anyone got a work around?
if ($file =~ /\.pdf$/i) {
print "$file is a pdf\n";
$fileLocation = "$directoryName/$file";
copyPDF("$fileLocation", "$file");
}
elsif ($file == '.') {
#print "argh\n";
}
else {
$openFolder = "$directory/$file";
print "*$openFolder";
openNextDirectory("$openFolder");
}
Always use
use strict; use warnings;!!!produces
because you are asking Perl to compare two numbers. You should be using
See
perldoc perlopfor more information about perl’s operators.