There are a couple of options.
One option is to create a thread for each file you want to monitor. If you go this route, check out the Thread::Queue module. You should run a search on this site for many good starting points. BrowserUK has given lots of advise and examples.
A second option is to monitor a directory and then make a copy if you receive an modification event. There is a module Win32::ReadDirectoryChangesW which will tell you which file was modified and allow you to respond. It is a wrapper around the Win32 API ReadDirectoryChangesW. It is not on CPAN but can be found on this site - so you will need to copy and paste the module into your personal library directory.
An short example, pieced from how I have used this module (untested).
use strict; use warnings; use Win32::ReadDirectoryChangesW; my $path = 'c:/directory'; my $subtree = 1; my $filter = FILE_ACTION_ADDED | FILE_ACTION_MODIFIED; my $rdc = Win32::ReadDirectoryChangesW->new(path => $path, subtree => 1, filter => $filter); my @results = $rdc->read_changes; while (scalar @results) { my ($action, $filename) = splice(@results, 0, 2); if ($action == FILE_ACTION_ADDED || $action == FILE_ACTION_MODIFIED +) { # perform your backup here } }
There is also a third option if you have more than one directory which would be to use both methods 1 and 2.
In reply to Re: File::Monitor problem with batch files
by tokpela
in thread File::Monitor problem with batch files
by xbmy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |