python文件目录压缩成tar.gz
2020-03-06 本文已影响0人
小王同学123321
直接上代码
压缩多个文件:
with tarfile.open("1582894835.tar.gz","w:gz") as tar:
for line in os.listdir("./1582894835"):
tar.add("./1582894835/"+line,arcname=os.path.basename("./1582894835/"+line))
压缩目录和压缩单个文件:
with tarfile.open("deal_dict.tar.gz","w:gz") as tar:
tar.add("1583302256",arcname=os.path.basename("1583302256"))