all Python 3shutilfunction
shutil.register_archive_format()
archives
Registers a custom archive format for make_archive(): a name is bound to a function that creates the archive.
Syntax
shutil.register_archive_format(name, function, extra_args=None, description='')
The function is called as function(base_name, base_dir, **kwargs) and must return the created file's name — make_archive returns exactly that. The registration lives only in the current process and silently replaces a format with the same name, even the built-in 'zip'. Unpacking needs a separate register_unpack_format — creation and unpacking formats are independent.
Examples
import os, shutil
def listing(base_name, base_dir, **kwargs):
path = base_name + '.lst'
with open(path, 'w') as f:
f.write('\n'.join(sorted(os.listdir(base_dir))))
return path
shutil.register_archive_format('lst', listing, description='file list')
os.mkdir('data')
open('data/a.txt', 'w').close()
print(shutil.make_archive('out', 'lst', base_dir='data')) # → out.lst
print(open('out.lst').read()) # → a.txt
See also
Open in the full glossarydocs.python.orgReport an inaccuracy