Check if a directory exists in a zip file with Python
Question: Initially I was thinking of using `os.path.isdir` but I don't think this works
for zip files. Is there a way to peek into the zip file and verify that this
directory exists? I would like to prevent using `unzip -l "$@"` as much as
possible, but if that's the only solution then I guess I have no choice.


Answer: You can check for the directories with
[ZipFile.namelist()](http://docs.python.org/library/zipfile.html#zipfile.ZipFile.namelist).

    
    
    import os, zipfile
    dir = "some/directory/"
    
    z = zipfile.ZipFile("myfile.zip")
    if dir in z.namelist():
        print "Found %s!" % dir
    

