Fedora 20中解决zip解压文件时中文文件名的乱码问题[已解决]

时间:2023-03-08 16:59:13

该方法的原文地址: http://wangqige.com/the-solution-of-unzip-files-which-zip-under-windows/(链接已失效)

Fedora 20中解决zip解压文件时中文文件名的乱码问题[已解决]

解决方法:保存如下Python代码到文件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()

使用方法如下:

python unzip.py *.zip