On Jan 15, 2008 12:13 PM, Charlie Farinella
<[EMAIL PROTECTED]> wrote:

> I need to monitor a directory and when a file is created, modify it.

The trouble isn't noticing when it's been created; the trouble is in
noticing when it's *done* being created. (I doubt whether this is
completely solved by inotify, but I hope it is.)

It's pretty simple to have your program notice any file that wasn't
there the previous time that it was run. But what if the program that
puts the file there has only put part of the file there yet?

Alas, there's no one solution. Sometimes the file format is one (like
XML) that shows end-of-data on its own. Sometimes the program writing
the file can be made to lock the file while writing it or to otherwise
signal when it is finished. Sometimes the solution is to move finished
files (atomically) into the target directory from a staging directory
on the same mounted volume. Sometimes the solution is to put only
symbolic links to finished files into the directory. Sometimes the OS
can tell you when the file has been written (but it can be fooled by,
e.g., a shell script or makefile that writes a file in chunks).
Sometimes it works to wait for a predetermined amount of time after
some event, then to assume (i.e. hope) that the file is finished. It
all depends upon what works best for your situation.

Good luck with it!

--Tom Phoenix
Stonehenge Perl Training

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to