create_archive()

audeer.create_archive(root, files, archive, *, verbose=False)[source]

Create ZIP or TAR.GZ archive.

If a list with files is provided, only those files will be included to the archive. In that case the files are added in the given order, which may have an influence on the checksum of the archive.

If files is set to None, all files below root will be added in sorted order. This includes hidden files and files from sub-folders, but not empty folders.

Parameters
  • root (str) – path to root folder of archive. Only files below root can be included and will be stored relative to root

  • files (Union[str, Sequence[str], None]) – files that will be included in the archive. Absolute and relative file paths are possible, as long as the files are below root. If set to None all files below root will be added to the archive

  • archive (str) – path to archive file. The type of the archive is determined from its file extension

  • verbose (bool) – if True a progress bar is shown

Raises

Examples

>>> _ = touch("a.txt")
>>> _ = touch("b.txt")
>>> create_archive(".", None, "archive.zip")
>>> extract_archive("archive.zip", ".")
['a.txt', 'b.txt']
>>> create_archive(".", ["a.txt"], "archive.tar.gz")
>>> extract_archive("archive.tar.gz", ".")
['a.txt']