title: Python: How to take tar using tarfile module by excluding the 3rd directory
body: <p>I have the directory structure like this </p>
  
  <pre><code>-- jenkins
  |-- jobs
  |   |-- dir1
  |   |   |-- build_dir--
  |   |   `-- Autoyes
  |   |-- dir2
  |   |   |-- build_dir--
  |   |   `-- Manyes
  |   |-- dir3
  |   |   |-- ArtFict
  |   |   `-- build_dir--
  |   `-- hi
  |-- tesst
  `-- tets
  </code></pre>
  
  <p>I need to take a tar using tarfile module by excluding the  <strong>"build_dir"</strong> under all <strong>dir1,dir2,dir3</strong> and more directories.
  I can use a very simple tar statement into subprocess to achieve this </p>
  
  <pre><code>tar --exclude="*/*/buid_dir" -czvf test.tgz jenkins
  </code></pre>
  
  <p>But I'm looking for a pythonic way to achieve this, so far what I have done is not excluding the "build_dir" directory.  </p>
  
  <pre><code>import tarfile
  import os,sys
  import subprocess
  
  def ProcesS (input):
      Asub = subprocess.Popen (input,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
      output,error = Asub.communicate()
      return output,error
  
  A = ['jenkins', 'jenkins/jobs', 'jenkins/jobs/dir1', 'jenkins/jobs/dir1/build_dir', 'jenkins/jobs/dir2', 'jenkins/jobs/dir2/build_dir', 'jenkins/jobs/dir3', 'jenkins/jobs/dir3/build_dir']
  
  Tar = tarfile.open('Backme.tgz','w:gz')
  
  #Tar.add(A,exclude='*/*/build_dir')   #This throws the error
  
  Tar.add(A)     # creates a tar file without excluding the build_dir 
  Tar.close()
  </code></pre>
  
  <p>It would be much helpful if someone finds the answer for this.</p>