|Welcome to the Monastery|
Determine when file is done being written?by EyeOpener (Scribe)
|on Jun 12, 2002 at 14:05 UTC||Need Help??|
EyeOpener has asked for the
wisdom of the Perl Monks concerning the following question:
Hello wise ones:
I've got a script which monitors a directory on an AIX system. If a new file is added, it opens the file, munges it around, and moves the original. Here is what the meaty part of the script looks like:
The problem is that the filename is grabbed before the file is completely written. If somewhat large files are FTP'd into this directory, the script tries to open the file while the FTP is in progress, and the script dies on the open IN line with the error "Cannot open or remove a file containing a running program."
Is there a file test I can use to determine whether the file is still being written, or is open by another process? Alternatively, it would suffice to trap the error and retry until the file is ready. I'm not really familiar with eval, and I can't find a good example of this kind of loop. Can anyone suggest a good approach? Thanks!