Given a tarball containing multiple directories, how do I extract just a single, specific directory?
import tarfile
tar = tarfile.open("/path/to/tarfile.tar.gz")
tar.list()
... rootdir/subdir_1/file_1.ext
... rootdir/subdir_1/file_n.ext
... rootdir/subdir_2/file_1.ext
etc.
How would I extract just the files from subdir_2?
NOTE: The entire operation is being done in memory a la...
import tarfile, urllib2, StringIO
data = urllib2.urlopen(url)
tar = tarfile.open(mode = 'r|*', fileobj = StringIO.StringIO(data.read()))
... so it's not feasible to extract all to disk and move the necessary folder.