Python 壓縮文件

def zipDir(dirpath, outFullName):    """    壓縮指定文件夾    :param dirpath: 目標文件夾路徑    :param outFullName: 壓縮文件保存路徑+xxxx.zip    :return: 無    """    # time.sleep(50)    zip = zipfile.ZipFile(outFullName, "w", zipfile.ZIP_DEFLATED)    for path, dirnames, filenames in os.walk(dirpath):        # 去掉目標跟路徑,只對目標文件夾下邊的文件及文件夾進行壓縮        fpath = path.replace(dirpath, '')        for filename in filenames:            zip.write(os.path.join(path, filename), os.path.join(fpath, filename))    zip.close()    print('壓縮成功!')
相關文章
相關標籤/搜索