[Tutor] Unzipping a Zip of folders that have zips within them that I'd like to unzip all at once.

Gregory Lund gnj091405 at gmail.com
Mon Sep 24 04:00:18 CEST 2012

>>> > You're trying to open the directory as if it were a zipfile. You should
>>> > pass in the path to a zipfile not to a folder.
>>> Agreed, but how do I do that "pass in the path to a zipfile'?
>>> Using an if statement I presume?
>>> > >
>>> > > I guess my first issue is to resolve the 'Permission denied' problem.
>>> > > And, I know I need an 'if' statement, somehow...
>>> >
>>> Yes, the permission denied problem seems to be the first real
>>> obstacle, but I can't figure it out.
>>> I tried searching online but everything I found to try, didn't work.
>> The permission error is because you are trying to open a folder as if it
>> were a file. The operating system does not give you permission to do this
>> because it is a nonsensical operation.
>>> > Remove the folder paths from the list of paths.
>>> How can I remove the folder paths from the list of paths?
>> You can do it with a list comprehension:
>> import os.path
>> paths = [p for p in paths if os.path.isdir(p)]
> Sorry that should be (note the 'not'):
> paths = [p for p in paths if not os.path.isdir(p)]
Ok, but where do I put that?
Sorry Oscar, I don't know where to put it, nor do I know how to use
'paths' once I do that.

I was trying this prior to getting your email about paths...(I put
this after z.close()

for item in zipContents:
    if item(-4) == ('.zip'):
        x = zipfile.Zipfile(item,'r')

but, I kept getting a "TypeError: 'str' object is not callable" error.

then I tried

for item in zipContents:
    if item.lower() .endswith(".zip"):

but got a "    item.extractall()
AttributeError: 'str' object has no attribute 'extractall'" error

Can't say I'm not trying. :-)
not working, but i'm trying whatever I can.

I greatly appreciate the help Oscar!


More information about the Tutor mailing list