This script saves the files as "/home/name/main/all my files and stuff". I want to save it as "main/all my files and stuff".
def zipit ():
file_paths = ['/home/name/main/']
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:
z.write(os.path.join(dir, f))
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
The problem is that
zipfilestores the complete path you are giving toZipFile.write. But you can modify the path in the zip with thearcnameparameter (ref).So you need just to strip off
'/home/name/'from the filename: