On 18 May 2005 17:30:58 -0700, "Lorn" <[EMAIL PROTECTED]> wrote:
>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: Here's your main problem. See replacement below. > zf =zipfile.ZipFile (fname, 'r') > for file in zf.namelist(): > newFile = open ( file, "wb") > newFile.write (zf.read (file)) > newFile.close() > zf.close() zipnames = filter(isfile, glob.glob('*.zip')) for zipname in zipnames: zf =zipfile.ZipFile (zipname, 'r') for zfilename in zf.namelist(): # don't shadow the "file" builtin newFile = open ( zfilename, "wb") newFile.write (zf.read (zfilename)) newFile.close() zf.close() Instead of filter, consider: zipnames = [x for x in glob.glob('*.zip') if isfile(x)] Cheers, John -- http://mail.python.org/mailman/listinfo/python-list