in reply to Some File::Find woes.
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Some File::Find woes.
by dominix (Deacon) on Jan 13, 2004 at 11:04 UTC | |
Re: Some File::Find woes.
by cLive ;-) (Prior) on Jan 13, 2004 at 05:03 UTC |