python .os.path.walk with direct file
<p>Everything in the <code>/home/username/main/books/</code> directory gets written and returned, but <code>/home/username/main/index.html</code> does not get written because "index.html" is not a directory and therefore cannot be walked. How would I revise the script to say if its a directory, walk it then write everything it finds, and if its direct file, write it.</p>

<p>python</p>

<pre><code>def zipit (request):
  file_paths = ['/home/username/main/books/', '/home/username/main/index.html']
  buffer= StringIO.StringIO()
  z= zipfile.ZipFile( buffer, "w" )
  for p in file_paths:
    for dir, subdirs, files in os.walk(p):
      for f in files:
        filename = os.path.join(dir, f)
        z.write(filename, arcname = filename[15:])
  z.close()
  buffer.seek(0)
  final = HttpResponse(buffer.read())
  final['Content-Disposition'] = 'attachment; filename=dbs_custom_library.zip'
  final['Content-Type'] = 'application/x-zip'
  return final
</code></pre>
