import tarfile # 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 locationarchive.close() |
File operations > File commands >