Message756

Author nobody
Recipients
Date 2002-10-10.18:37:07
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
I have been trying to use zipfile.ZipFile() with mode="a" 
to add files to an archive. 

However when I try to perform a write, each file simply 
overwrites the previous one. 

I have tried exactly the same code in Python 2.2 and it 
works differently. For instance, in Jython, opening a non-
existent zip file with mode="a" creates the file, whereas 
a runtime error is generated if you perform the same 
action in Python, which requires the file to be present. If 
I create the file, open it with mode="a" and write files to 
the archive, this works fine with Python. 

Perhaps someone out there can verify that this is indeed 
a bug, or perhaps I am doing somthing wrong. 

I have attached some code to explain below. 

import zipfile 

#File c:\\test.zip does not exist... 
file = zipfile.ZipFile("c:\\test.zip", mode="a") 

#Above, if done in Python, creates a runtime error! 

#Add first file to archive 
file.write("c:\\test1.txt") 

#Add second file to archive 
file.write("c:\\test2.txt") 

file.close() 

#Oh dear, appears that archive now just consists of  
#c:\\test2.txt 

In the meantime the bug can be got around by reading in 
the zip file contents if it exists, then opening the same 
zip file in write mode, copying back the contents then 
adding the new file.
History
Date User Action Args
2008-02-20 17:17:10adminlinkissue621502 messages
2008-02-20 17:17:10admincreate