In this article we will discuss different ways to get detail about all files in a zip archive like file’s name & size etc.

Get the name of all files in the ZIP archive using ZipFile.namelist()

In Python’s zipfile module, ZipFile class provides a member function to get the names of all files in it i.e.

It returns a list of file names in Zip archive.

Let’s use this to get the list of files in a zip file ,

First of all, import the module,

Create a ZipFile object by opening the ‘’ in read mode and get the list of files in it using ZipFile.namelist() i.e.


As it returns only the names of file in archive. But if we want more details like size, last modification etc of all entries in zip archive?

Let’s see how to do that,

Get detail info like name, size etc of files in a Zip file using ZipFile.infolist()

In Python’s zipfile module ZipFile class provides an another member function to the get the details of each entry in zipfile i.e.

It returns a list of ZipInfo objects for each member of the archive.

Each ZipInfo object for a file in archive contains many information about the file like name, last modification time , permission & size etc.

Let’s use this to to iterate over all the files in zip & print details like name, size, compressed size & last modification datetime.


Print the details of ZIP archive to std.out using ZipFile.printdir()

In Python’s zipfile module ZipFile class provides another member function to print the contents of zip file as table i.e.

It will print the details of files in ZIP archive, as tabular format in std.out .
Let’s see an example,


Complete example is as follows,




Python Recommendations:

C++ & C++11 Recommendations:

If you didn't find what you were looking, then do suggest us in the comments below. We will be more than happy to add that.

Subscribe with us to join 1500+ Python & C++ developers, to get more Tips &  Tutorials like this.