in reply to Re^3: Question in Win32::ChangeNotify...
in thread Question in Win32::ChangeNotify...


Hi guys!

I have one more question on this:

How can i invoke ChangeNotify on multiple events? I tried using LAST_WRITE | SIZE - but it gave me an error! For me, LAST_WRITE almost takes care of all my issues but there's one event that i HAVE to take care of - 'file deletion' event! How do i achieve that? I should be notified when a file in a specific directory gets deleted by someone!

Thanks
  • Comment on Re^4: Question in Win32::ChangeNotify...

Replies are listed 'Best First'.
Re^5: Question in Win32::ChangeNotify...
by BrowserUk (Patriarch) on Jul 14, 2008 at 15:05 UTC

      Thanks for the reply

      .. and could you pls tell me how i can use both FILE_NAME and LAST_WRITE in the same ChangeNotify's wait()statement?

        You specify the flags on the constructor:

        $notify = Win32::ChangeNotify->new($path, $subtree, 'FILE_NAME | LAST_ +WRITE' );

        $nofify->wait; will return for either type of event. It's then up to you to go off and find what changed by scanning the directory in question.

        To simplify the discovery, you can create mutiple notify objects and then wait_any() (from Win32::Event), and then you what type of change you should look for:

        use Win32::Event qw[ wait_any ]; ... my $notifyFileName = Win32::ChangeNotify->new($path, $subtree, 'FILE_N +AME' ); my $notifyLastWrite = Win32::ChangeNotify->new($path, $subtree, 'LAST_ +WRITE' ); my @nfys = ( $notifyFileName, $notifyLastWrite ); defined( my $signalled = wait_any( @notify, $timeout ) ) or die "Mutex error: $^E"; if( $signalled == 1 ) { ## Look for fine name change } elsif( $signalled == 2 ) { ## Look for last write change } elsif( $signalled < 0 ) { warn "Abaindoned mutex"; ## ? } else { ## Wait timed out (only if timeout used) }

        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.