Neill Taylor wrote: > > I am writing a script which will poll a directory and then move any files > in the directory to a new directory dependant upon its name. > > The problem I think I might have is that the script may try to pick a file > that is still being copied into the directory whilst the application is > still trying to write the file. > > What is the best method in Perl to prevent errors.
Hi Neill. If your application is well-behaved then it may lock the file for writing. If your Perl program asks for an exclusive lock then it will be granted if it no longer being accessed. Take a look at perldoc -f flock Another way is to check the size of file. A file will often show a size of zero until it is closed by the writing application. Finally, if only one file at a time is being written then just sort the them in order of creation date and move all but the latest one. What works you will find only by experimentation. HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>