Search code examples
pythonarchivezip

Reading multiple zip archive comments with python


My zip file contains a lot of smaller zip files.

I want to iterate through all those files, reading and printing each of their comments.

I've found out that zipfile file.zip or unzip -z file.zipcan do this to a file in separate, but I'm looking for a way to go through all of them.

Couldn't find anything perfect yet, but this post. However, the code is too advanced for me, and I need something very basic, to begin with :)

Any ideas or information would be great, thanks!


Solution

  • Not sure exactly what your looking for but here are a few ways I did it on an Ubuntu Linux machine.

    for i in `ls *.zip`; do unzip -l $i; done
    

    or

    unzip -l myzip.zip
    

    or

    unzip -p myzip.zip | python -c 'import zipfile,sys,StringIO;print     "\n".join(zipfile.ZipFile(StringIO.StringIO(sys.stdin.read())).namelist())'