Hello monks,
I've got a Windows2K file server with over 2 million pdf files. We want to delete any of these pdfs more than X days old (X seems to keep changing). So, I wrote up a script (below) to automate this; I'm using ActivePerl 5.6.
My problem is that the script seems to cause the system to eat up all it's "system cache" memory! The perl process only seems to use nominal amount of memory. I blame Windows 2000, but has anyone else seen this problem? Anything in my script that stands out as bad?
### Delete pdf files older than X days from given directory tree ###
use strict;
use warnings;
use File::Find;
my @directories;
$directories[0] = $ARGV[0];
my $days_old = $ARGV[1];
finddepth(\&wanted, @directories);
# File::Find coderef
# Find all PDFs older than given # of days & delete
sub wanted {
# Turn forward slashes into backslashes to make real Win32 paths
my $file = $File::Find::name;
$file =~ s|/|\\|g;
if ( ($file =~ m|\.pdf$|) && (int(-M $file) > $days_old) ) {
print "Found: $file, deleted\n";
unlink($file) || print "Unable to delete $file!\n";
}
}
Thanks in advance,
ibanix
$ echo '$0 & $0 &' > foo; chmod a+x foo; foo;
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|