用例
在linux中解压文件后,出现文件名的中文不能正常的显示。
1.在待解压的文件夹下新增文件
vi unzip.py
内容
#!/usr/bin/env python
# -*- coding;utf-8 -*-
import os
import sys
import zipfile
print "Processing File " + sys.argv[1]
file=zipfile.ZipFile(sys.argv[1],"r");
for name in file.namelist():
utf8name=name.decode('gbk')
print "Extracting " + utf8name
pathname = os.path.dirname(utf8name)
if not os.path.exists(pathname) and pathname!= "":
os.makedirs(pathname)
data = file.read(name)
if not os.path.exists(utf8name):
fo = open(utf8name, "w")
fo.write(data)
fo.close
file.close()
2.保存后执行如下命令
python unzip.py *.zip
在Ubuntu 14.10下解压zip文件出现乱码的解决:http://www.linuxdiyf.com/linux/9952.html
Linux下用vi打开文件出现乱码:http://www.linuxdiyf.com/linux/1023.html