Determining when a file has finished copying

Daniel Mahoney dan at catfolks.net
Wed Jul 9 17:12:12 EDT 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
> described.
> 
> Any thoughts? Thanks!
> Doug

Could you maybe us the os module to call out to lsof to see if anyone
still has the target file open? I am assuming that when the write process
finishes writing it would close the file.

Check "man lsof"





More information about the Python-list mailing list