-
-
Save parkjinwoo/9b94b6cc441943caaa43 to your computer and use it in GitHub Desktop.
This file contains 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: | |
with open(encfname, 'wb') as outfile: | |
shutil.copyfileobj(zfile.open(f), outfile) | |
except IOError: | |
directory = os.path.dirname(encfname) | |
if not os.path.exists(directory): | |
os.makedirs(directory) | |
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
Less efficient way as it always check the existence of the same directory for all files that the directory contains. 😄 That was my intention of checking IOError instead of checking the existence. Not a big deal though.