Categories
Python Answers

How to create a zip archive of a directory with Python?

Spread the love

Sometimes, we want to create a zip archive of a directory with Python.

In this article, we’ll look at how to create a zip archive of a directory with Python.

How to create a zip archive of a directory with Python?

To create a zip archive of a directory with Python, we can use the shutil.make_archive method.

For instance, we write

import shutil

shutil.make_archive(output_filename, 'zip', dir_name)

to call shutil.make_archive with the output_filename of the zip archive, 'zip', and the dir_name of the folder to zip.

Conclusion

To create a zip archive of a directory with Python, we can use the shutil.make_archive method.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

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