On Thursday 24 January 2008, [EMAIL PROTECTED] wrote: > Charlie Farinella <[EMAIL PROTECTED]> writes: > > > On Wednesday 16 January 2008, Peter Scott wrote: > >> On Tue, 15 Jan 2008 15:13:29 -0500, Charlie Farinella wrote: > >> > I need to monitor a directory and when a file is created, modify it. > >> > I've been playing with Linux::Inotify2 and may be able to make that > >> > work, but am wondering if this is something that people do > > routinely.
> Charlie, > Have you encountered having to do this on MS-windows OS? If you have > can you tell a little about how to set it up? This isn't Windows, but here is what I have, it seems to work, maybe it will help you. Any pointers on coding improvements are also welcome. :-) ============== #!/usr/bin/perl -w ### Monitor a directory for .wav files moved into the directory ### and convert them to .ogg. (cf - 2008-01-17) use strict; use Linux::Inotify2; ### Declare the variables my $datetime = localtime(); my $logfile = '/home/cfarinella/logfile'; my $wavdir = '/home/cfarinella/dropdir'; my $oggdir = '/home/cfarinella/oggdir'; ### Define an Inotify2 instance my $inotify = new Linux::Inotify2 or die "Unable to create new inotify object: $!"; $inotify->watch ( $wavdir, IN_MOVED_TO ) or die "watch creation failed"; ### Open the logfile for writing open( LOGFILE, ">>$logfile" ); ### Monitor the defined directory and if a .wav file is moved into it ### convert that file to .ogg format in a different directory. Write ### the result to the logfile. while() { my @events = $inotify->read; unless ( @events > 0 ) { print "read error: $!"; last; } foreach( @events ) { my @path = split( /\//, $_->fullname ); my $infile = pop( @path ); if( $infile =~ '.wav' ) { my @array = split( /\./, $infile ); my $outname = $array[0]; print LOGFILE "$datetime: $wavdir/$infile converted to $oggdir/$outname.ogg\n"; `oggenc $wavdir/$infile -Q -o $oggdir/$outname.ogg`; } } } close( LOGFILE ); ============== > > I spent most of a day trying to find something that will notice when > files are created but recursively. I found vbs scripts that I know > nothing about but only one directory [no recusion], but wondered if > perl can do it on the MS-windows OS. > > I expected there to be lots of good tools since it would seem kind of > natural for security oriented software to be able to notice file > creation. > > There are tools out there but one must download and try usually only > to find it is something really sorry like `foldmonkey' or the like. > > Even with perl running from linux on a cifs mount would be ok. If > that situation is capable of handling whatever it needs to with > MS-windows OS. > > Maybe File::AnySpec? > > I wasn't able to make heads of tails of the Description on cpan. > (probably not their fault) > > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > http://learn.perl.org/ > > > > -- ------------------------------------------------------------------------ Charles Farinella Appropriate Solutions, Inc. (www.AppropriateSolutions.com) [EMAIL PROTECTED] voice: 603.924.6079 fax: 603.924.8668 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/