title: Overwriting previously extracted files instead of creating new ones
body: <p>There are a few libraries used to extract archive files through Python, such as gzip, zipfile library, rarfile, tarfile, patool etc. I found one of the libraries (patool) to be especially useful due to its cross-format feature in the sense that it can extract almost any type of archive including the most popular ones such as ZIP, GZIP, TAR and RAR.</p>
  
  <p>To extract an archive file with patool it is as easy as this:</p>
  
  <pre><code>patoolib.extract_archive( "Archive.zip",outdir="Folder1")
  </code></pre>
  
  <p>Where the <code>"Archive.zip"</code> is the path of the archive file and the <code>"Folder1"</code> is the path of the directory where the extracted file will be stored.</p>
  
  <p>The extracting works fine. The problem is that if I run the same code again for the exact same archive file, an identical extracted file will be stored in the same folder but with a slightly different name (filename at the first run, filename1 at the second, filename11 at the third and so on.</p>
  
  <p>Instead of this, I need the code to overwrite the extracted file if a file under a same name already exists in the directory.</p>
  
  <p>This <code>extract_archive</code> function looks so minimal - it only have these two parameters, a <code>verbosity</code> parameter, and a <code>program</code> parameter which specifies the program you want to extract archives with.</p>
  
  <p><strong>Edits:</strong>
  Nizam Mohamed's answer documented that <code>extract_archive</code> function is actually overwriting the output. I found out that was partially true - the function overwrites ZIP files, but not GZ files which is what I am after. For GZ files, the function still generates new files.</p>
  
  <p><strong>Edits</strong>
  Padraic Cunningham's answer suggested using the <a href="https://github.com/wummel/patool/tree/master/patoolib" rel="nofollow">master source</a> . So, I downloaded that code and replaced my old patool library scripts with the scripts in the link. Here is the result:</p>
  
  <pre><code>os.listdir()
  Out[11]: ['a.gz']
  
  patoolib.extract_archive("a.gz",verbosity=1,outdir=".")
  patool: Extracting a.gz ...
  patool: ... a.gz extracted to `.'.
  Out[12]: '.'
  
  patoolib.extract_archive("a.gz",verbosity=1,outdir=".")
  patool: Extracting a.gz ...
  patool: ... a.gz extracted to `.'.
  Out[13]: '.'
  
  patoolib.extract_archive("a.gz",verbosity=1,outdir=".")
  patool: Extracting a.gz ...
  patool: ... a.gz extracted to `.'.
  Out[14]: '.'
  
  os.listdir()
  Out[15]: ['a', 'a.gz', 'a1', 'a2']
  </code></pre>
  
  <p>So, again, the <code>extract_archive</code> function is creating new files everytime it is executed. The file archived under <code>a.gz</code> has a different name from <code>a</code> actually.</p>