Brothers,
I am continuing some of my file maintenance scripts, and noticed that either Windows or Perl has some severe speed issues while working with tens of thousands of files in a directory.
It takes 30 seconds, to 5 minutes to read in the list of files depending on the size, 10k files, or 400k files roughly. I know Windows, and especially NTFS does not perform well with that number, but I was looking for a faster directory reading function.
It appears VBScript can do a "getnext" on files, without getting in the full list. Is there something like that available in Perl?
Its likely I am not reading the directory correctly, but I can't find the difference between opendir and readdir, and just using chdir and doing a foreach loop.
See my code below:
use strict;
use POSIX;
use File::Copy;
use File::Basename;
use File::stat;
my $src;
my $dst;
print "\nEnter Source Directory: ";
chomp($src = <STDIN>);
$dst = $src;
$dst =~ s/inbox/queue/g;
print "\nDESTINATION DIRECTORY SET TO: $dst\n";
chdir $src || die "Can't chdir to !\n" ;
my $count;
my $limit;
print "\nEnter File Limit: ";
chomp($limit = <STDIN>)
$count = 1;
for my $file (<*.imap>)
{
$count = $count + 1;
my ($name,$path,$suffix) = fileparse($file,"\.imap") ;
my $info = stat($file);
my $datestamp = strftime("%Y%m%d", localtime($info->mtime));
mkdir "$dst\\$datestamp" or "Error making Directory $!\n";
print "\n Moving \"$file\" >> $dst\\$datestamp";
move $file,"$dst\\$datestamp\\$name$suffix" or warn "Cannot copy $
+file $!\n";
if($count > $limit)
{
print "\n \nFile Limit Reached. Stopping\n";
exit;}
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.