Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: File::Monitor problem with batch files

by xbmy (Friar)
on Nov 18, 2010 at 00:41 UTC ( #872100=note: print w/ replies, xml ) Need Help??


in reply to Re: File::Monitor problem with batch files
in thread File::Monitor problem with batch files

Your code just stop immediately after running, I think it need at least one loop as while (1){ ..... } or something, but after i added the while loop, it still not work for me, it looks like the code i have posted. Thanks anyway!


Comment on Re^2: File::Monitor problem with batch files
Re^3: File::Monitor problem with batch files
by Khen1950fx (Canon) on Nov 18, 2010 at 02:20 UTC
    It actually was working just as it should work. I called scan twice, so it shut down. I don't think that you need a while loop. For example, you can turn on the monitor, and it will dutifully observe what it's supposed to watch:
    #!/usr/bin/perl use strict; use warnings; use File::Monitor; my @Files = qw(1.doc 2.doc 3.xls); my $wFileMonitor = File::Monitor->new(); foreach my $wFile(@Files){ $wFileMonitor->watch($wFile); } $wFileMonitor->scan;
    Now the monitor is on. It will stay on until you call the second scan---then it reports the changes and shuts off.

      Sounds good. Thanks!

      But what i want is the "monitor always on" during the period of which i compose my files, the code monitor my "saving" action and then copy the new modified file to the newpath automatically.

      Your code does work well after i added a while loop, but just for the first file in the "@Files" list, after i modified and saved the second and third file, there was no response.

      May be i didn't totally understand you, please don't hesitate to let me know!

      Finally, it worked! I tried like this use the file::monitor::delta package:

      use File::Monitor; use File::Copy::Recursive qw(fcopy rcopy dircopy fmove rmove dirmove); my $monitor = File::Monitor->new(); # Watch some files for my $file (qw( 1.doc 2.xls)) { $monitor->watch( $file ); } # First scan just finds out about the monitored files. No changes # will be reported. #$object->scan; while (1) { $monitor->scan; sleep 10; # After the first scan we get a list of File::Monitor::Delta objec +ts # that describe any changes my @changes = $monitor->scan; for my $change (@changes) { # Call methods on File::Monitor::Delta to discover what change +d if ($change->is_mtime) { my $name = $change->name; my $old_mtime = $change->old_mtime; my $new_mtime = $change->new_mtime; print "$name changed at $new_mtime\n"; fcopy ("$name","p:\\phdpaper"); #backup automatically for +the file which just has been modified } } }

      Thank you for your help!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://872100]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2014-12-21 22:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (108 votes), past polls