Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

If your running Win32 then Win32::ChangeNotify makes this very easy.

#! perl -slw use strict; use Win32::ChangeNotify; my $path = 'p:\test'; my $notify = Win32::ChangeNotify->new( $path, 0, 'FILE_NAME' ); my %last; @last{ glob $path . '/*' } = (); while( 1 ) { print('Nothing changed'), next unless $notify->wait( 10_000 ); # Check every 10 seconds $notify->reset; print $/, 'Something changed'; my @files = glob $path . '/*'; if( @files < scalar keys %last ) { delete @last{ @files }; print 'These files where deleted: '; print for keys %last; print''; } elsif( @files > scalar keys %last ) { my %temp; @temp{ @files } = (); delete @temp{ keys %last }; print 'These files where created: '; print for keys %temp; print''; } else { print "A non-deletion or creation change occured"; } undef %last; @last{ @files } = (); } __END__ P:\test>changenotify Nothing changed Nothing changed Something changed These files where created: p:\test/fred Nothing changed Nothing changed Something changed These files where deleted: p:\test/fred Nothing changed Nothing changed Nothing changed Nothing changed

You'll need control-break rather than ^C to interupt this script.

To extending this to monitor the whole subtree, change the 0 in the new() call to 1, though you'll need some extra work to find out what changed where.

I'm not aware of a similar mechanism under *nix.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
If I understand your problem, I can solve it! Of course, the same can be said for you.


In reply to Re: how to permanently monitor a directory by BrowserUk
in thread how to permanently monitor a directory by LupoX

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2024-04-18 18:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found