From: Girish on
Hello All,

I am using Python 2.5. How do I extract all the files and directories
in a zip file?

Thanks in advance..

-Girish
From: Steven D'Aprano on
On Wed, 21 Jul 2010 23:35:32 -0700, Girish wrote:

> Hello All,
>
> I am using Python 2.5. How do I extract all the files and directories in
> a zip file?

import zipfile
z = zipfile.ZipFile("test.zip", mode="r")
for internal_filename in z.namelist():
contents = z.read(internal_filename)
open(internal_filename, 'w').write(contents)
z.close()

Or upgrade to Python 2.6 and use the extractall method:

http://docs.python.org/library/zipfile.html#zipfile.ZipFile.extractall





--
Steven