I'm having problems with the archive that I created using the zipfile in Python. I repeat all the files in the directory and write them to the archive. When I try to retrieve them after this, I get an exception related to the path separator.
the_path= "C:\\path\\to\\folder"
zipped= cStringIO.StringIO()
zf = zipfile.ZipFile(zipped_cache, "w", zipfile.ZIP_DEFLATED)
for dirname, subdirs, files in os.walk(the_path) :
for filename in files:
zf.write(os.path.join(dirname, filename), os.path.join(dirname[1+len(the_path):], filename))
zf.extractall("C:\\destination\\path")
zf.close()
zipped_cache.close()
Here's an exception:
zipfile.BadZipfile: the file name in the directory "env \ index" and the header "env / index" are different.
Update: I replaced the string buffer cStringIO.StringIO()with a temporary file ( tempfile.mkstemp("temp.zip")), and now it works. Something happens there when the zipfile module writes to a buffer that corrupts the archive, but is not sure what the problem is.
, / / , "r" / "w" "rb" / "wb". Linux, Windows - . . >