Skip to content

Instantly share code, notes, and snippets.

@midnightradio
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save midnightradio/e106497ed345638546f2 to your computer and use it in GitHub Desktop.
Save midnightradio/e106497ed345638546f2 to your computer and use it in GitHub Desktop.
unarchiving a zip file with fixing unicode filename corrupted by windows zip archivers.
#!/usr/bin/env python
# coding: utf-8
from __future__ import unicode_literals, print_function
import sys, zipfile, shutil, os, fileinput
def inflate(filename):
print(filename)
zfile = zipfile.ZipFile(filename)
for f in zfile.namelist():
encfname = unicode(f,'cp949')
print(encfname)
try:
outfile = open(encfname, 'wb')
except IOError:
os.makedirs(os.path.dirname(encfname))
outfile = open(encfname, 'wb')
finally:
shutil.copyfileobj(zfile.open(f), outfile)
outfile.close()
if __name__ == '__main__':
inflate(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment