Py 3.6 tarfile
Klaus Jantzen
k.d.jantzen at mailbox.org
Sat Sep 23 13:18:58 EDT 2017
Hi,
if I understand the documentation of the tarfile module correctly writing
TarfileObject.add(".../path/to/filename", recursive=False)
means that the directory structure of the file object will not be included
in the archive.
In the following script only "testtext1.pdf" is stored outside a directory
structure. The other files are always stored in a directory structure;
using recursive=False does not have any effect.
============
#!/usr/bin/env python3
#
import argparse
import sys
import tarfile
import os
arch = "Archive.tgz"
os.unlink(arch)
try:
TO = tarfile.open(name=arch, mode='x:gz') # Tarfile object
TO.add("testtext1.pdf")
TO.add("./testtext2.pdf")
TO.add("./testtext3.pdf", recursive=False)
TO.add("./files/testtext4.pdf")
TO.add("./files/testtext5.pdf", recursive=False)
TO.close()
except FileExistsError as err:
pass
=========
Is my understanding correct or what do have to do so that the files are
stored without any directory information?
Thanks for any hints.
--
K.D.J.
More information about the Python-list
mailing list