import os
import tarfile

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()

 

import os
import tarfile


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))

make_targz("/opt/bp/maps/map_0116.tar.gz","/opt/bp/maps/map_0116")

 

相关文章:

  • 2022-01-14
  • 2022-01-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-19
  • 2022-12-23
猜你喜欢
  • 2021-08-18
  • 2022-12-23
  • 2021-07-29
  • 2021-09-06
  • 2022-12-23
相关资源
相似解决方案