marks542...@yahoo.com wrote:
Hi, I am using the zipfile in Python 2.4 to extract files from
existing zips.
It appears to work but the files extracted are corrupt.
Have you done any analysis to see in what sense they are corrupt? For
example, do text files work, but not binary ones? If the file fragment
is small, are you getting a zero-length file out? Is the filesize
always wrong?
Here is my code :
import zipfile
import os, sys , shutil
epath = "c:/ziptest/"
fil = "J:/archives/xzips/duplicates/gothicfence_1470.zip"
ferr = file((epath + "/errlog.txt"),"w")
print "Extracting to ",epath
try:
if zipfile.is_zipfile(fil):
z = zipfile.ZipFile(fil,"r")
nmes = z.namelist()
for i in nmes:
fn = os.path.split(i)[1]
print "...",fn
dta = z.read(i)
You read the data here, but don't use it. So the subsequent read below
presumably misses this first part of the data.
if len(dta) >0 :
enam = epath + fn
fo = file(enam,"wb")
fo.write(z.read(i))
fo.flush()
fo.close()
except:
myerr = fil +"," + str(sys.exc_info()[1]) +"\n"
ferr.write(myerr)
ferr.close()
any ideas ? thanks
In addition, I don't know if Zipfile.read() might return only a portion
of the file. If so, you'll need to make a loop instead of a simple if
in that final fragment.
--
http://mail.python.org/mailman/listinfo/python-list