title: Python tar.add files but omit parent directories
body: <p>I am trying to create a tar file from a list of files stored in a text file, I have working code to create the tar, but I wish to start the archive from a certain directory (app and all subdirectories), and remove the parents directories. This is due to the software only opening the file from a certain directory.</p>
  
  <p>package.list files are as below:</p>
  
  <p><code>app\myFile
  app\myDir\myFile
  app\myDir\myFile2</code></p>
  
  <p>If I omit the path in <code>restore.add</code>, it cannot find the files due to my program running from elsewhere. How do I tell the tar to start at a particular directory, or to add the files, but maintain the directory structure it got from the text file, e.g starting with <code>app</code> not all the parent dirs</p>
  
  <p>My objective is to do this <code>tar cf restore.tar -T package.list</code> but with Python on Windows.</p>
  
  <p>I have tried <code>basename</code> from here: <a href="https://stackoverflow.com/questions/21137539/how-to-compress-a-tar-file-in-a-tar-gz-without-directory">How to compress a tar file in a tar.gz without directory?</a>, this strips out ALL the directories. </p>
  
  <p>I have also tried using <code>arcname='app'</code> in the .add method, however this gives some weird results by breaking the directory structure and renames loads of files to <code>app</code></p>
  
  <pre><code>path = foo + '\\' + bar
  file = open(path +  '\\package.list', 'r')
  restore = tarfile.open(path +  '\\restore.tar', 'w')
  for line in file:
      restore.add(path + '\\' + line.strip())
  restore.close()
  file.close()
  </code></pre>
  
  <p>Using Python 2.7</p>