can tarfile maintain directory structure?

Lars Gustaebel lars at gustaebel.de
Wed Aug 18 11:01:48 CEST 2004


On Tue, 17 Aug 2004 21:06:45 -0500, Jeff Epler wrote:

> You can use os.walk (or os.path.walk for older versions of Python) to
> recurse a directory tree.  Here's a simple script to use tarfile and
> os.walk:
> [snip]

Far too complicated... tarfile.py is rather high-level:

import tarfile

tar = tarfile.open(filename, "w:gz")
tar.add(directory)
tar.close()

The add() method is recursive by default. More information and examples
here: http://docs.python.org/lib/module-tarfile.html

-- 
Lars Gustäbel
lars at gustaebel.de




More information about the Python-list mailing list