Win32::ChangeNotify - Monitor events related to files and directories
require Win32::ChangeNotify; $notify = Win32::ChangeNotify->new($Path,$WatchSubTree,$Events); $notify->wait or warn "Something failed: $!\n"; # There has been a change.
This module allows the user to use a Win32 change notification event object from Perl. This allows the Perl program to monitor events relating to files and directory trees.
Unfortunately, the Win32 API which implements this feature does not provide any indication of what triggered the notification (as far as I know). If you're monitoring a directory for file changes, and you need to know which file changed, you'll have to find some other way of determining that. Depending on exactly what you're trying to do, you may be able to check file timestamps to find recently changed files. Or, you may need to cache the directory contents somewhere and compare the current contents to your cached copy when you receive a change notification.
The wait method and wait_all & wait_any functions are inherited from the "Win32::IPC" module.
wait
wait_all
wait_any
Constructor for a new ChangeNotification object. $path is the directory to monitor. If $subtree is true, then all directories under $path will be monitored. $filter indicates what events should trigger a notification. It should be a string containing any of the following flags (separated by whitespace and/or |).
$path
$subtree
$filter
|
ATTRIBUTES Any attribute change DIR_NAME Any directory name change FILE_NAME Any file name change (creating/deleting/renaming) LAST_WRITE Any change to a file's last write time SECURITY Any security descriptor change SIZE Any change in a file's size
($filter can also be an integer composed from the FILE_NOTIFY_CHANGE_* constants.)
FILE_NOTIFY_CHANGE_*
Shut down monitoring. You could just undef $notify instead (but close works even if there are other copies of the object). This happens automatically when your program exits.
undef $notify
close
Resets the ChangeNotification object after a change has been detected. The object will become signalled again after the next change. (It is OK to call this immediately after new, but it is not required.)
new
See "Win32::IPC". Remember to call reset afterwards if you want to continue monitoring.
reset
Win32::ChangeNotify still supports the ActiveWare syntax, but its use is deprecated.
Use
$Obj = Win32::ChangeNotify->new($PathName,$WatchSubTree,$Filter)
instead.
Use $obj->reset instead.
$obj->reset
Use $obj->close instead.
$obj->close
Christopher J. Madsen <cjm@pobox.com>
Loosely based on the original module by ActiveWare Internet Corp., http://www.ActiveWare.com
To install Win32, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Win32
CPAN shell
perl -MCPAN -e shell install Win32
For more information on module installation, please visit the detailed CPAN module installation guide.