Unable to Concatenate a file - destination kept getting overwritten

Foster Rilindo rilindo at me.com
Fri Apr 20 21:03:25 EDT 2012


I can't seem to concatenate.

I got binary files here:

yvaine:disk rilindo$ ls -lah
total 61440
drwxr-xr-x   4 rilindo  staff   136B Apr 20 19:47 .
drwxr-xr-x  10 rilindo  staff   340B Apr 20 19:45 ..
-rw-r--r--   1 rilindo  staff    20M Apr 20 20:00 disk1
-rw-r--r--   1 rilindo  staff    10M Apr 20 19:47 disk2

Based on the following code, I should be able to cat disk2 over to disk 1, resulting in a 30 Meg file:

>>> import shutil
>>> import os
>>> disk1="/Users/rilindo/tmp/disk/disk1"
>>> disk2="/Users/rilindo/tmp/disk/disk2"
>>> destination = open(disk1,'wb')
>>> shutil.copyfileobj(open(disk2,'rb'),destination)
>>> destination.close()

However, the result is that the destination gets overwritten:

yvaine:disk rilindo$ ls -lah
total 40960
drwxr-xr-x   4 rilindo  staff   136B Apr 20 19:47 .
drwxr-xr-x  10 rilindo  staff   340B Apr 20 19:45 ..
-rw-r--r--   1 rilindo  staff    10M Apr 20 20:02 disk1
-rw-r--r--   1 rilindo  staff    10M Apr 20 19:47 disk2

Is this right way to concatenate a file or is there a better way?

 - Rilindo



More information about the Python-list mailing list