import tarfile, os def make_tar(folder_to_backup, dest_folder, compression='bz2'): if compression: dest_ext = '.' + compression else: dest_ext = '' arcname = os.path.basename(folder_to_backup) dest_name = '%s.tar%s' % (arcname, dest_ext) dest_path = os.path.join(dest_folder, dest_name) if compression: dest_cmp = ':' + compression else: dest_cmp = '' out = tarfile.TarFile.open(dest_path, 'w'+dest_cmp) out.add(folder_to_backup, arcname) out.close( ) return dest_path
在Python下使用gzip压缩文件
最新推荐文章于 2024-07-02 17:23:19 发布