Extracting multiple zip files in a directory

Lorn efoda5446 at yahoo.com
Wed May 18 20:30:58 EDT 2005


I've been working on this code somewhat succesfully, however I'm unable
to get it to iterate through all the zip files in the directory. As of
now it only extracts the first one it finds. If anyone could lend some
tips on how my iteration scheme should look, it would be hugely
appreciated. Here is what I have so far:

import zipfile, glob, os

from os.path import isfile
fname = filter(isfile, glob.glob('*.zip'))
for fname in fname:
    zf =zipfile.ZipFile (fname, 'r')
    for file in zf.namelist():
        newFile = open ( file, "wb")
        newFile.write (zf.read (file))
        newFile.close() 
    zf.close()




More information about the Python-list mailing list