title: Python How to copy files inside a zip to another zip in memory?
body: <p><strong>Purpose</strong></p>
  
  <p>Split a zip archive into smaller zip archives with an evenly distributed # of files per new zip.</p>
  
  <p><strong>Example</strong></p>
  
  <p>source zip (100 files)</p>
  
  <ul>
  <li>src/100-Test.zip</li>
  </ul>
  
  <p>destination zips (25 files each): </p>
  
  <ul>
  <li>destination/1.zip   </li>
  <li>destination/2.zip</li>
  <li>destination/3.zip</li>
  <li>destination/4.zip</li>
  </ul>
  
  <p><strong>Description</strong></p>
  
  <p>So I have been able to open the zip file and iterate through the contents to split them up, but I have not been able to write to the file. Since I didn't do anything with the zip contents I didn't think I had to do any StringIO stuff or anything?</p>
  
  <p><strong>Code</strong></p>
  
  <pre><code>zipFileNameSrc = '100-Test.zip'
  zipFile = open(zipFileNameSrc)
  unzippedFile = zipfile.ZipFile(zipFile)
  imgList = [(s, unzippedFile.read(s)) for s in unzippedFile.namelist() if (".jpg" or ".JPG") in s]
  #image names: imgList[i][0]  and  images: imgList[i][1]
  
  #...
  #...additional logic to split into sets of 25 images
  #...fileTuplesList = imgList[:25]
  zipNo = 1
  #zipFileDest = destination + "/" + zipSrcNm + "/" + zipNo.__str__() + ".zip"
  zipFileName = zipNo.__str__() + ".zip"
  zipOut = zipfile.ZipFile(zipFileName, 'w')
  for i in xrange(len(fileTuplesList)):
      fileNameAndPath = fileTuplesList[i][0]
      actualFile = fileTuplesList[i][1]
      zipOut.write(fileNameAndPath, actualFile)
  zipOut.close()
  #move_files(zipFileName, zipFileDest)
  </code></pre>
  
  <p><strong>Error</strong> </p>
  
  <p>I get on this on line <code>zipOut.write(fileNameAndPath, actualFile)</code></p>
  
  <blockquote>
    <p>OSError: [Errno 2] No such file or directory: '100-Test/17.jpg'</p>
  </blockquote>
  
  <p><strong>Bonus</strong></p>
  
  <p>How to save the zip file to a different folder than where my script is?</p>