Extracted files form zip corrupted

A

Astley Le Jasper

I want to batch extract files from a directory of zips. The thing is
that the files are excel spreadsheets. I don't want to read them in
python, just dump them as extracted files in another directory.
However, when I do a test the excel file becomes corrupted. Any clues?

import zipfile

zf = zipfile.ZipFile('C:\Temp\mytest.zip')
filename = 'spreadsheet.xls'

data = zf.read(filename)

uz_file = 'C:\Temp\' + filename
f = open(uz_file, "w")
f.write(data)
f.close()
 
M

MRAB

Astley said:
I want to batch extract files from a directory of zips. The thing is
that the files are excel spreadsheets. I don't want to read them in
python, just dump them as extracted files in another directory.
However, when I do a test the excel file becomes corrupted. Any clues?


import zipfile

zf = zipfile.ZipFile('C:\Temp\mytest.zip')
filename = 'spreadsheet.xls'

data = zf.read(filename)

uz_file = 'C:\Temp\' + filename

Be careful of backslashes in strings!
f = open(uz_file, "w")

Open as a binary file:

f = open(uz_file, "wb")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top