58微招聘是怎么制作的:解决ubuntu下解压windows下生成的zip压缩包中文文件名乱码问题

来源:百度文库 编辑:中财网 时间:2024/04/29 15:44:11

解决ubuntu下解压windows下生成的zip压缩包中文文件名乱码问题

Category: 小程序 — kevin_xiong @ 13:37

 

用python写的,算是我写的第一个python程序了。
使用方法:./unzipgbk.py zipfilename.zip

代码如下:
#!/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()

文件下载

Technorati 标签: zip, ubuntu, 乱码, python