You don't need to use File::Find for this at all. Further, you don't need to use absolute paths, and you don't need to convert "/" to "\". Windows understands "/" in file paths for a long time now.
#!/usr/bin/perl -w
# this code only partially tested
my($dir) = $ARGV[0] ||'';
my($maxage) = $ARGV[1] ||0; $maxage = int $maxage;
die "Can't operate without a target directory spec. Op aborted.\n"
unless length $dir; # dir could be named "0"
die qq[No such directory "$dir"\n] unless -e $dir;
die "Need max allowed age spec for files. Op aborted.\n"
unless $maxage; # zero values and non-numeric values not accepted.
local *PDFDIR;
opendir(PDFDIR, $dir) or die $!;
my(@files) = grep(/\.pdf$/, readdir(PDFDIR));
closedir(PDFDIR) or warn $!;
print qq[Nothing to do. No files present in "dir".\n] and exit unless
+ @files;
foreach (@files) {
print qq[Skipping directory "$dir/$_"\n] if -d $_;
unlink $dir . '/' . $_ if int(-M $dir . '/' . $_) > $maxage
or die qq[Can't unlink "$dir/$_"! $!];
print qq[Deleted "$dir/$_"\n];
}
print "Done.\n\n" and exit;
--
Tommy Butler, a.k.a. TOMMY