Determining when a file has finished copying
larry.bates at websafe.com`
Wed Jul 9 22:49:02 CEST 2008
> Thanks for your replies, they are helpful. I should have included in
> my initial question that I don't have as much control over the program
> that writes (pgm-W) as I'd like. Otherwise, the write to a different
> filename and then rename solution would work great. There's no way to
> tell from the os.stat() methods to tell when the file is finished
> being copied? I ran some test programs, one of which continously
> copies big files from one directory to another, and another that
> continously does a glob.glob("*.pdf") on those files and looks at the
> st_atime and st_mtime parts of the return value of os.stat(filename).
> From that experiment it looks like st_atime and st_mtime equal each
> other until the file has finished being copied. Nothing in the
> documentation about st_atime or st_mtime leads me to think this is
> true, it's just my observations about the two test programs I've
> Any thoughts? Thanks!
I guess the problem is "What is the definition of 'finished copying'?". There
is no explicit operating system command that says "I'm done copying to this file
and I won't add anything on to the end of it".
If I could not control the sending application, I would make an estimation of
how long the longest file could possibly take to copy, double it and then only
look at files where the st_ctime was at least that far in the past. What you
suggest could work as well.
More information about the Python-list