title: How to Write a File to the Root Directory of a Zip File in Python
body: <p>I'm trying to replace a file in a zipped archive with a script using <code>zipfile</code>.  The file is one directory, the archive is in another.  To do this, I copy everything from the original archive into another, excluding the file I want to replace.  Then I write the new version of the file to replace into the new archive, close it, and delete the old archive and rename the new one.  Should be easy, right? <strong><em>Wrong.</em></strong></p>
  
  <p>For whatever reason, the <code>zipfile.write()</code> method has this silly thing it does where it assumes that the second (optional) argument, <code>arcname</code> is the same as your file name, unless you specify it.  So, if I have the following:</p>
  
  <pre><code>fileName = "C:\\Documents\\file"
  archive.write(fileName)
  </code></pre>
  
  <p>I will get an archive with a subarchive called "Documents", and within that will be the file.  I want the file to be in the root directory of the archive (sidenote: is 'root directory' the right term for what I'm refering to?)</p>
  
  <p>Thing's I've Tried:</p>
  
  <ul>
  <li><code>archive.write(fileName,'')</code>  This produced a weird file in the archive, which could not be opened.</li>
  <li><code>archive.write(fileName, archive)</code> I really thought this would work, but the system <strong><em>really</em></strong> didn't like it.  </li>
  <li><code>archive.write(fileNameWithoutPath)</code> This one returned an error, since Python could no longer find the file.</li>
  </ul>
  
  <p>So how do I specify that I want to put the file in the root directory of the archive and still specify its path so Python can find it?</p>
  
  <p>Minor, and semi-related question: Is there a way to create the new archive such that it is hidden in windows explorer?</p>