Filesys::Notify::Win32::ReadDirectoryChanges - read/watch directory changes
my $watcher = Filesys::Notify::Win32::ReadDirectoryChanges->new(); for my $dir (@ARGV) { $watcher->watch_directory( path => $dir, subtree => 1 ); }; $watcher->wait(sub { my( $event ) = @_; say $event->{action}, ":", $event->{path}; });
This module allows to watch multiple directories for changes and invokes a callback for every change.
This module spawns a thread for each watched directory. Each such thread synchronously reads file system changes and communicates them to the main thread through a Thread::Queue.
->new %options
my $w = Filesys::Notify::Win32::ReadDirectoryChanges->new( directories => \@ARGV, subtree => 1, );
Creates a new watcher object.
->queue
my $q = $w->queue;
Returns the Thread::Queue object where the filesystem events get passed in. Use this for integration with your own event loop.
->watch_directory
$w->watch_directory( path => $dir, subtree => 1 );
Add a directory to the list of watched directories.
->unwatch_directory
$w->unwatch_directory( path => $dir );
Remove a directory from the list of watched directories. There still may come in some events stored for that directory previously in the queue.
->wait $CB
$w->wait(sub { my ($event) = @_; say $event->{action}; say $event->{path}; });
Synchronously wait for file system events.
The following events are created by ReadDirectoryChangesW resp. this module
{ action => 'added', path => 'old-name.example', }
A new file was created
{ action => 'removed', path => 'old-name.example', }
A file was removed
{ action => 'modified', path => 'old-name.example', }
A file was modified
{ action => 'old_name', path => 'old-name.example', }
First half of a rename
{ action => 'new_name', path => 'new-name.example', }
Second half of a rename
Whenever the event old_name is followed immediately by new_name, a third, synthetic event is generated, renamed.
renamed
{ action => 'renamed', path => 'old-name.example', old_name => 'old-name.example', new_name => 'new-name.example', }
In theory, this module should also work on Cygwin, but for some reason, it seems that there is memory corruption on Cygwin. If you happen to be handy with a debugger and familiar with Cygwin, your help is appreciated.
Filesys::Notify::Simple - simple cross-platform directory watcher
File::ChangeNotify - complex cross-platform directory watcher
Win32::ChangeNotify - Win32 directory watcher using the ChangeNotify API
Currently, no additional information like that available through https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-readdirectorychangesexw|ReadDirectoryChangesExW is collected. But a wrapper/emulation could provide that information whenever RDCE is unavailable (on Windows versions before Windows 10).
The public repository of this module is https://github.com/Corion/Filesys-Notify-Win32-ReadDirectoryChanges.
The public support forum of this module is https://perlmonks.org/.
Max Maischein corion@cpan.org
corion@cpan.org
Copyright 2022 by Max Maischein corion@cpan.org.
This module is released under the same terms as Perl itself.
To install Filesys::Notify::Win32::ReadDirectoryChanges, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Filesys::Notify::Win32::ReadDirectoryChanges
CPAN shell
perl -MCPAN -e shell install Filesys::Notify::Win32::ReadDirectoryChanges
For more information on module installation, please visit the detailed CPAN module installation guide.