Detecting open files and forcing closure

MRAB google at mrabarnett.plus.com
Fri Jan 9 21:57:56 EST 2009


Andrew Robert wrote:
> Hi Everyone,
> 
> We have a process that does a copy of a share from one location to
> another.
> 
> This usually works fine but can occasionally bomb if a file is opened
> by a user somewhere.
> 
> Is there a way to code detection of open files and force a close?
> 
> The files in question are typically PDF files if that matters.
> 
> Any pointers you can provide on this would be greatly appreciated.
> 
If the file is open then an exception will be raised. You could catch
it, sleep a while, and then retry, or continue with the other files and
then come back to it and retry. It might take more than one retry.
Anyway, it's a bad idea to force a close, even if that's possible.



More information about the Python-list mailing list