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

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.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^8: Question in Win32::ChangeNotify...
by biswanath_c (Beadle) on Jul 14, 2008 at 16:20 UTC

    Thanks a lot for the reply. It finally worked for me!

    But i have one more issue now:

    To analyse the changes done to the directory that i am monitoring, i create snapshot files b4 and after the change and i compare them - that's how i find out what exactly has changed

    The problem is this:

    after each notification and comparison of the snapshot files, i delete the snapshot files by using this piece of code:

    $cmd = "del snapshot*.txt";


    if(system($cmd))

    {

    print "delete failed\n";

    }

    else

    {

    print "delete snapshot*.txt successful!\n";

    }


    The file deletion works fine if i run the script from the command line; but when i run the script from the task scheduler, it just does not delet the files! Would anybody know why?

    Thanks

      Probably a permissions issue. Ie. You will need to schedule the script to run as a user with permission to delete the files. How you do that will depend upon how you are scheduling the script. Ie. RTFM :)


      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.