how to tar with python
Brian McCann
Brian.McCann at viziant.net
Fri Aug 24 09:03:30 EDT 2007
Hi,
I'm trying to tar the contents of a directory "test" which contains
3 files foo1.xml ,foo2.xml, foo3.xml
in my current directory /home/pythonbox/tmp I have the directory "test"
if I run the below script it fails with the below error, but the files exist in the directory test
any help would be greatly appreciated
--Brian
##################################
[tmp]$ ./tarup.py
Traceback (most recent call last):
File "./tarup.py", line 29, in ?
tfile .add(f)
File "/usr/lib64/python2.4/tarfile.py", line 1229, in add
tarinfo = self.gettarinfo(name, arcname)
File "/usr/lib64/python2.4/tarfile.py", line 1101, in gettarinfo
statres = os.lstat(name)
OSError: [Errno 2] No such file or directory: 'viz2.xml'
###################################
import string
import os
import shutil
import tarfile
tfile = tarfile.open("files.tar.gz", 'w:gz')
files = os.listdir("test")
for f in files:
tfile .add(f)
tfile.close
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070824/5311dcc9/attachment.html>
More information about the Python-list
mailing list