Extract a seris of tar files into self titled directories
<p>I have a series of tar files that I wish to extract their containing data into a new directory. I want this directory to be an edited version of the original tar file name. </p>

<pre><code>import tarfile
import glob
import os

for file in glob.glob("*.tar"):
    # Open file
    tar = tarfile.open(file, "r:")
    # Create new diretory with name of tar file (minus .tar)
    new_dir = file[0:-4]
    os.makedirs(new_dir)
    tar.extractall()
    os.chdir(new_dir)
</code></pre>

<p>This works fine up until the <code>tar.extractall()</code> part. Is there a way to directly extract the tar file into the target directory or am I forced to extract all and then move the files across?</p>

<p>new_dir = "path"</p>

<p><code>tar.extractall(path=new_dir)</code></p>

python tar