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

后端 未结 25 2994
暗喜
暗喜 2020-11-22 07:12

How can I create a zip archive of a directory structure in Python?

25条回答
  •  故里飘歌
    2020-11-22 08:06

    For adding compression to the resulting zip file, check out this link.

    You need to change:

    zip = zipfile.ZipFile('Python.zip', 'w')
    

    to

    zip = zipfile.ZipFile('Python.zip', 'w', zipfile.ZIP_DEFLATED)
    

提交回复
热议问题