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

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

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

25条回答
  •  一生所求
    2020-11-22 08:03

    Use shutil, which is part of python standard library set. Using shutil is so simple(see code below):

    • 1st arg: Filename of resultant zip/tar file,
    • 2nd arg: zip/tar,
    • 3rd arg: dir_name

    Code:

    import shutil
    shutil.make_archive('/home/user/Desktop/Filename','zip','/home/username/Desktop/Directory')
    

提交回复
热议问题