basic directory watcher - sanity check

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I use activestate and they dont support with my version of perl Cpan
directory watcher.. is there a better way to watch a directory for a
file and then process it than the below, perl, shareware, or through a
low cost product ?  The infinite loop code below causes my windows
server 2003 to have strange behavior after its been running a few days
(blinking screen, requiring reboot, etc).  I know its related b/c when
this service is stopped, the system is fine.  I checked File Monitor
also but you still need something that continuously checks something,
the array in its case...

while (1) {
@filelist = split(/\n/, $var = `dir /A-D /B /O-D e:\mail\inboxes\
    foreach (@filelist) {
        sleep 3;

Re: basic directory watcher - sanity check

Quoted text here. Click to load it

replace this with

my @filelist = ...;

Now, instead of invoking a shell, you can do:


use strict;
use warnings;

while ( 1 ) {
    opendir my $dir, '.';
    my @files = grep { ! /^.$/ } readdir $dir;
    for my $file ( @files ) {
        dobasicstuff( $file );
        movefile( $file );
    closedir $dir;
    sleep 3;


Alternatively, you can try to use the Win32 API Function

There is a CPAN module to do that:

(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW: /

Re: basic directory watcher - sanity check

Quoted text here. Click to load it

Hi ok I tried the cpan module you suggested - it worked great on
Windows XP, but then on Windows Server 2003 where I need it (both
running 5.8.8 activestate perl, I get this error:
Couldn't create Win32::ChangeNotify object

Why ?
Code snippet straight from CPAN causing the issue:
use strict;
   use POE;
   use POE::Component::Win32::ChangeNotify;

   my $poco = POE::Component::Win32::ChangeNotify->spawn( alias =>
'blah' );

        package_states => [
                'main' => [ qw(_start notification) ],

Site Timeline