basic directory watcher - sanity check

J

Jack

Hi

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=();
@filelist = split(/\n/, $var = `dir /A-D /B /O-D e:\\mail\inboxes\
\testbox`);
foreach (@filelist) {
dobasicstuff();
movefile();
sleep 3;
}
 
A

A. Sinan Unur

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=();
@filelist = split(/\n/, $var = `dir /A-D /B /O-D e:\\mail\inboxes\
\testbox`);

replace this with

my @filelist = ...;

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

#!/usr/bin/perl

use strict;
use warnings;

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

__END__

Alternatively, you can try to use the Win32 API Function
FindFirstChangeNotification

http://msdn.microsoft.com/en-us/library/aa364417(VS.85).aspx

There is a CPAN module to do that:
http://search.cpan.org/~cjm/Win32-IPC-1.07/lib/Win32/ChangeNotify.pm


--
A. Sinan Unur <[email protected]>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
 
J

Jack

replace this with

my @filelist = ...;

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

#!/usr/bin/perl

use strict;
use warnings;

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

}

__END__

Alternatively, you can try to use the Win32 API Function
FindFirstChangeNotification

http://msdn.microsoft.com/en-us/library/aa364417(VS.85).aspx

There is a CPAN module to do that:http://search.cpan.org/~cjm/Win32-IPC-1..07/lib/Win32/ChangeNotify.pm

--
A. Sinan Unur <[email protected]>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:http://www.rehabitation.com/clpmisc/

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' );

POE::Session->create(
package_states => [
'main' => [ qw(_start notification) ],
],
);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top