问题
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