Determining when a file has finished copying

Ethan Furman ethan at stoneleaf.us
Wed Jul 9 19:54:05 EDT 2008


writeson wrote:
> Guys,
> 
> 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

The solution my team has used is to monitor the file size.  If the file 
has stopped growing for x amount of time (we use 45 seconds) the file is 
done copying.  Not elegant, but it works.
--
Ethan



More information about the Python-list mailing list