zipfile extracting png files corrupt

marks542004 at yahoo.com marks542004 at yahoo.com
Sat Oct 17 01:22:03 EDT 2009


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.
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)
                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



More information about the Python-list mailing list