Fixed issue with extractZip function.

This commit is contained in:
echel0n 2014-06-19 10:04:16 -07:00
parent f9b9fd23c2
commit 5f7b8465d0

View file

@ -1183,18 +1183,20 @@ def extractZip(archive, targetDir):
if not os.path.exists(targetDir): if not os.path.exists(targetDir):
os.mkdir(targetDir) os.mkdir(targetDir)
with zipfile.ZipFile(archive) as zip_file: zip_file = zipfile.ZipFile(archive, 'r')
for member in zip_file.namelist(): for member in zip_file.namelist():
filename = os.path.basename(member) filename = os.path.basename(member)
# skip directories # skip directories
if not filename: if not filename:
continue continue
# copy file (taken from zipfile's extract) # copy file (taken from zipfile's extract)
source = zip_file.open(member) source = zip_file.open(member)
target = file(os.path.join(targetDir, filename), "wb") target = file(os.path.join(targetDir, filename), "wb")
with source, target: shutil.copyfileobj(source, target)
shutil.copyfileobj(source, target) source.close()
target.close()
zip_file.close()
return True return True
except: except:
return False return False