import zipfile
import os
def zip_pack(target, filePath):
if not target.endswith(".zip"):
target = target + '{}'.format('.zip')
zipFilePath = os.path.basename(target).split('.')[0]+"/{}".format(os.path.basename(filePath))
with zipfile.ZipFile(target, 'a') as z:
if os.path.exists(filePath) and os.path.isfile(filePath):
z.write(filePath,zipFilePath)
return zipfile
if __name__ == '__main__':
downloads_ = '/Users/mbh/Downloads/平凡的世界 | 路遥 著 (张震 杨晨倾情演绎,独家首发) - 新经典'
zip_pack(downloads_,
'/Users/mbh/Downloads/平凡的世界 | 路遥 著 (张震 杨晨倾情演绎,独家首发) - 新经典/0001. 【限时福利】领取经典文学大礼包,免费收听《霍乱时期的爱情》.m4a')
Python zipfile 打包超级实用
猜你喜欢
转载自blog.csdn.net/mbh12333/article/details/105585569
今日推荐
周排行