Well,
A stupid error on my part. I was never incrementing my array index ($i)
while building the array.
Anyways, I've run into a different problem.
While traversing the directory tree, the script dies attempting to create
the 48 entry in the array.
Does anyone know if there is a limit in the number of ChangeNotify objects
one can create?
I'm running Build 522 on Windows 2000 Professional with 384MB ram.
--- BEGIN SCRIPT ---
use strict;
use Win32::ChangeNotify;
use Win32::MAPI qw(Yes);
use File::Find; # module that handles recursively scanning dirs for us
# --- GLOBALS START ---
my ($filter) = "FILE_NAME|LAST_WRITE|SIZE"; # look for change in file name,
last modified time and file size
my $notify; # index for @dirs, indicates which object got triggered
my (@dirs) = []; # array of ChangeNotify objects
my (@names) = []; # array of dir names for reporting
my ($i) = 0; # index needed during population of arrays
# --- GLOBALS END ---
find ( \&finder, @ARGV); # recursively populate @dirs with ChangeNotify
objects for any dirs found
while (1) {
print STDERR "Watching...\n";
$notify = Win32::ChangeNotify::wait_any(@dirs) or die "Could not wait!:
$!";
$notify--; # decrement by one. changenotify returns 1 based index while
array are 0 based
print STDERR "$notify\n";
&message($notify);
$dirs[$notify]->reset() or die "Could not reset object $notify:$!"; #
reset the object
}
# --- subs ---
sub finder {
# used by File::Find to process files found in the directories
# this reads in the file looking for a line eq $look and then parses the
rest of the file
my ($file) = $_; # name of subdirectory or file
my ($path) = $File::Find::name; # get path with file/dir name
return if (-f $file); # skip files
$names[$i] = $path;
$dirs[$i] = Win32::ChangeNotify->new ($path, 1, $filter) or die "Failed
creating ChangeNotify object: $!";
$i++;
print STDERR "Registered $path\n";
}
sub message {
my($obj)=new Win32::MAPI(UseDefProfile=>Yes);
my %message = ();
my ($i) = shift;
$message{To} = ['[EMAIL PROTECTED]'];
$message{Subject} = "[Perlbot] Something changed on QAWEB1";
$message{Text} = "This is an automated message.\n The size, contents, or
last changed date of a file on server has changed in $names[$i]\n";
$obj->Send(\%message);
undef $obj;
}
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Ed
Moon
Sent: Friday, September 29, 2000 7:10 PM
To: '[EMAIL PROTECTED]'
Subject: Win32::ChangeNotify::wait_any?
I'm having problems with the following script run as 'notify.pl k:'
I want to monitor a mounted share and all sub directories for any file
changes. If I monitor just the root directory (with '$notify->wait or warn
"Something failed: $!\n";) it works.
But I want more granular notification and used the wait_any function.
If I copy a file into a monitored directory, wait_any never seems to
trigger.
Anyone know what I'm doing wrong?
_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users