[Tutor] tar a directory
Bill Nolf
bn58243 at gmail.com
Thu Nov 3 13:56:59 EDT 2016
python version 2.6.6
I'm trying to tar/gzip a directory, the directory is defined as an variable
I want to tar and gzip the directory archive in the example below:
import tarfile
dirarchive = /a/b/c/archive
Test 1
tar.add(dirarchive)
Error: name 'tar' not defined
Test 2
tarfile.add(dirarchive)
Error: 'module' object has no attribute add
Test 3
archive = tarfile.open(dirachive, "a:gz")
archive.add=(dirarchive)
archive.close()
Error: IOError [Errono 21] Is a directory: /a/b/c/archive
Test 4
archive = tarfile.open("test.tgz", "a:gz")
archive.add=(dirarchive, arcname="test")
archive.close()
Create a gzip file called test.tgz in the current directory, which is close
but no cigar
What I would like is the following gzip file:
/a/b/c/archive.tgz
More information about the Tutor
mailing list