create_archive()¶
- audeer.create_archive(root, files, archive, *, verbose=False)[source]¶
Create ZIP or TAR archive.
If a list with
filesis 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
filesis set toNone, all files belowrootwill 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 belowrootcan be included and will be stored relative torootfiles (
UnionType[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 toNoneall files belowrootwill be added to the archivearchive (
str) – path to archive file. The type of the archive is determined from its file extensionverbose (
bool) – ifTruea progress bar is shown
- Raises
FileNotFoundError – if
rootor a file infilesis not foundNotADirectoryError – if
rootis not a directoryRuntimeError – if archive does not end with
zip,tar,tar.gz,tar.bz2,tar.xzRuntimeError – if a file in
filesis not belowroot
Examples
>>> file_a = audeer.touch("a.txt") >>> folder = os.path.dirname(file_a) >>> file_b = audeer.touch(folder, "b.txt") >>> archive = audeer.path("archive.zip") >>> audeer.create_archive(folder, None, archive) >>> audeer.extract_archive(archive, ".") ['a.txt', 'b.txt'] >>> archive = audeer.path("archive.tar.gz") >>> audeer.create_archive(folder, ["a.txt"], archive) >>> audeer.extract_archive(archive, ".") ['a.txt']