in reply to Re: Directory Monitor
in thread Directory Monitor

Corion I have added short code , problem with event not email

#! usr/bin/perl use strict; use warnings; use File::Monitor; use File::Monitor::Delta; use File::Monitor::Object; my $path="/tmp/abc"; my $monitor = File::Monitor->new(); # Watch a directory $monitor->watch( { name => $path, recurse => 1 } ); # First scan just finds out about the monitored files. No changes # will be reported. $monitor->scan; # Later perform a scan and gather any changes while ($path) { my @changes = $monitor->scan; for my $file ( @changes ) { chomp($file); my @file_changes; my @file_list; if($file->is_event('size')){ print "size change\n\n"; } if ($file->is_size) { my $name = $file->name; my $old_size = $file->old_size; my $new_size = $file->new_size; print "$name has changed size from $old_size to $new_size\ +n"; } } }

Replies are listed 'Best First'.
Re^3: Directory Monitor
by Corion (Patriarch) on Jul 25, 2016 at 11:00 UTC

    Personally, before checking for changes in file size, I would check and print what kinds of events the monitor sends you. Unfortunately, there is no easy way to ask the Delta about what it contains, so you will have to look at the raw contents using Data::Dumper and hope that they show what kinds of events get triggered by a change:

    for my $change (@changes) { use Data::Dumper; warn "Got a change:"; warn Dumper $change;

    Also, why are you calling chomp on an element of @changes? What do you expect @changes to contain?

      But The event is not working while update the file in the directory

      # Called when file size changes $monitor->callback( size => sub { my ($file_name, $event, $change) = @_; warn "$file_name has changed size\n"; } );

        Yes. Maybe the output of Data::Dumper could help to see whether there was any event raised when a file is changed.

        I'm not sure what could make the module fail to notice a change, but maybe you're working in the wrong directory?