Last active
August 29, 2015 14:08
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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