shutil.copyfile is incomplete (truncated)

Neil Cerutti neilc at norwich.edu
Thu Apr 11 14:53:30 EDT 2013


On 2013-04-11, Rob Schneider <rmschne at gmail.com> wrote:
> Using Python 2.7.2 on OSX, I have created a file in temp space,
> then use the function "shutil.copyfile(fn,loc+fname)" from "fn"
> to "loc+fname".
>
> At the destination location, the file is truncated. About 10%
> of the file is lost.  Original file is unchanged.
>
> I added calls to "statinfo" immediately after the copy, and all
> looks ok (correct file size).
>
> filecmp.cmp(fn,loc+fname)
> print "Statinfo    :"+fn+":\n", os.stat(fn)
> print "Statinfo    :"+loc+fname+":\n", os.stat(loc+fname)
>
> But when I look at the file in Finder, destination is smaller
> and even looking at the file (with text editor) file is
> truncated.
>
> What could be causing this?

Could fn be getting some changes written after the copy is made?

Is the file flushed/closed before you copy it?

-- 
Neil Cerutti



More information about the Python-list mailing list