I am working with zip archives, using the zipfile module to extract all the files with certain file extensions from each zip. In these zip archives the files I'm after all have their own path information, but I would like to extract the files I want into one simple directory without recreating the path information in the original archive. Here's the relevant snippet of code that does the extracting:
currentzip = zipfile.ZipFile(os.path.join(zdir, zfile), mode='r') innernames = currentzip.namelist() for name in innernames: if name[-3:] in extensionsiwant: currentzip.extract(name, destdir) currentzip.close()
zdir is the directory with the zip archives, and zfile is the archive it's working on at the moment. extensionsiwant is a list of the three-character file extensions I am interested in extracting from the archive and destdir is the directory I want to dump all the unzipped files into.
It works great, except it creates all these sub directories inside the destination directory when all I want is files.
I suppose it wouldn't be hard to write more code to move all the files and delete all the unwanted directories, but it seems like the zipfile module ought to be able to just extract the files how I want them the first time around.