python 打包成tar包

def make_targz(output_filename, source_dir):
with tarfile.open(output_filename, "w:gz") as tar:
tar.add(source_dir, arcname=os.path.basename(source_dir))
def make_targz_one_by_one(output_filename, source_dir):
tar = tarfile.open(output_filename,"w:gz")
for root,dir,files in os.walk(source_dir):
for file in files:
pathfile = os.path.join(root, file)
tar.add(pathfile)
tar.close()
make_targz("test.tar.gz","a.txt") 

#or

make_targz_one_by_one("test.tar.gz","a.txt")
上一篇:c# thread pause example


下一篇:php面向对象学习笔记01-面向对象介绍、构造函数、析构函数