Your hint of checking "tar.getnames()" was exatly what I needed. It returns the path to where the file will be extracted (ie. Src/ver/qfw/symbols.xml). After knowing this fact it was quite simple to extract the file.
Thanks, problem solved!!! Emile Boudreau x5754 -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Carsten Haese Sent: Tuesday, April 03, 2007 1:42 PM To: python-list@python.org Subject: Re: Extracting a file from a tarball On Tue, 2007-04-03 at 13:26 -0400, Boudreau, Emile wrote: > I am trying to extract one file from a tarball, without success. This > is the code I'm using to open the tarball and extract the file: > > tar = tarfile.open(component+'-win32-app-'+bestVersion+'-dev.tar.gz', > 'r') > extractedFile = tar.extractfile('symbols.xml') > > And this is my error: > > Traceback (most recent call last): > File "C:\CognosInstalls\AutoTest\PollDir.py", line 121, in <module> > main() > File "C:\CognosInstalls\AutoTest\PollDir.py", line 119, in main > extract('c:\\', 'I:\\daily\\'+components[i], components[i]) > File "C:\CognosInstalls\AutoTest\PollDir.py", line 27, in extract > filelike = tar.extractfile('symbols.xml') > File "C:\Python25\lib\tarfile.py", line 1488, in extract > tarinfo = self.getmember(member) > File "C:\Python25\lib\tarfile.py", line 1171, in getmember > raise KeyError("filename %r not found" % name) > KeyError: "filename 'symbols.xml' not found" > > I know that the tarball contants this file "symbols.xml" What does tar.getnames() return? -Carsten -- http://mail.python.org/mailman/listinfo/python-list This message may contain privileged and/or confidential information. If you have received this e-mail in error or are not the intended recipient, you may not use, copy, disseminate or distribute it; do not open any attachments, delete it immediately from your system and notify the sender promptly by e-mail that you have done so. Thank you. -- http://mail.python.org/mailman/listinfo/python-list