tools.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:auditwheel 作者: pypa 项目源码 文件源码
def dir2zip(in_dir, zip_fname):
    """ Make a zip file `zip_fname` with contents of directory `in_dir`

    The recorded filenames are relative to `in_dir`, so doing a standard zip
    unpack of the resulting `zip_fname` in an empty directory will result in
    the original directory contents.

    Parameters
    ----------
    in_dir : str
        Directory path containing files to go in the zip archive
    zip_fname : str
        Filename of zip archive to write
    """
    z = zipfile.ZipFile(zip_fname, 'w', compression=zipfile.ZIP_DEFLATED)
    for root, dirs, files in os.walk(in_dir):
        for file in files:
            fname = os.path.join(root, file)
            out_fname = os.path.relpath(fname, in_dir)
            z.write(os.path.join(root, file), out_fname)
    z.close()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号