List all the files in a Zip file using Python 3

Published by admin on

Python list all files in a zip file

List all the files in a zip file using python 3 :

In this tutorial, we will learn how to find out all the files of a zip file. For that, we will use ‘zipfile‘ library which is already available in the ‘python‘ package. We will have to use ‘import zipfile’. Using this module, we can create, read, write,append and list all the files from a Zip file.

One thing to be noted that this module cannot be used with multi disk zip files. Let’s take a look in to the program :

import zipfile

zip_file = zipfile.ZipFile('','r')

for name in zip_file.namelist():
    print ('%s' % (name))


Steps Used :

1. import ‘zipfile‘ module
2. Create one new object by passing the zip file path and read (r) or write (w) mode like zipfile.ZipFile(‘file_path’,’r’) .
3. It will return list of all files inside that zip file.
4. Run one ‘for‘ loop and print out all the names of the files.
5. Finally, close the object by using .close() method.

Similar tutorials :

Categories: python


Leave a Reply

Your email address will not be published. Required fields are marked *