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 toNone
, all files belowroot
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 belowroot
can be included and will be stored relative toroot
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 belowroot
. If set toNone
all files belowroot
will be added to the archivearchive (
str
) – path to archive file. The type of the archive is determined from its file extensionverbose (
bool
) – ifTrue
a progress bar is shown
- Raises
FileNotFoundError – if
root
or a file infiles
is not foundNotADirectoryError – if
root
is not a directoryRuntimeError – if archive does not end with
zip
ortar.gz
or a file infiles
is not belowroot
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']