File operations‎ > ‎File commands‎ > ‎

tar




import tarfile

Create tar.gz archive and add files

# add files without considering original folder/directory structure
archive = tarfile.open("myarchive.tar.gz", "w:gz") # create new tar archive (gzip compressed write access w:gz)
archive.add("path/to/file.txt", arcname="newfilename.txt") # rename files, ignoring original directory location
archive.close()