How to Extract Zip Files with non-Unicode non-Latin Filenames?

蹲街弑〆低调 提交于 2020-01-02 07:04:53

问题


Sometimes you come by Zip files with file or directory with some unrecognized characters in the names so you can't extract them. What tools do you use to extract them in properly converted filenames?


回答1:


I searched the web but failed to find a good script. So out of necessity I wrote a Python script myself. Hope it comes handy for someone.

Any suggestions are welcome, especially if you know this will not work in some special cases. Please don't pick on the untidy coding style.

import os,sys,zipfile

x, fn = sys.argv
enc = 'utf-8'

zipf = zipfile.ZipFile(fn)
for x in zipf.infolist():
    fn = x.filename
    fne = fn.encode(enc)
    if os.sep in fne:
        path = fne[:fne.rindex(os.sep)]
        if not os.path.exists(path): os.makedirs(path)
    if fne.endswith(os.sep): continue
    f = open(fne,'wb')
    f.write(zipf.open(fn).read())
    f.close()


来源:https://stackoverflow.com/questions/11295835/how-to-extract-zip-files-with-non-unicode-non-latin-filenames

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!