creating a tar file with python

John McMonagle jmcmonagle at
Fri Aug 24 06:20:49 CEST 2007

Brian McCann wrote:
> Hi,
> I'm trying to create a tar file of the contents of the current directory
> right now there is only one file "text.xml" in the current dir,  I'm 
> using"." current dir as source
> but that gives syntax error
> any help would be greatly appreciated
> --Brian
> #!/usr/bin/python
> import string
> import os
> import sys
> import time
> import errno
> import shutil
> import tarfile
> tar =,"test.tar.gz", "w:gz)

Contents of current directory in a new gzipped tarfile (includes 
"hidden" *nix files):

import tarfile, glob
t ='tarfilename.tar.gz', 'w:gz')
for filename in glob.glob('*')+glob.glob('.*'):

Note: this includes any subdirectories and their files below the current 



More information about the Python-list mailing list