Menu Close

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

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.

Posted in Python, Python Answers