-
Notifications
You must be signed in to change notification settings - Fork 0
/
gbkzip
executable file
·39 lines (34 loc) · 994 Bytes
/
gbkzip
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python
#-*- coding:utf8 -*-
'''
gbkzip - unzip Windows zip file and convert gbk to utf8
author: YUCOAT(yucoat^yucoat.com)
date: 2012-9-28
homepage: www.yucoat.com
If you find any bug please contact me, thank you!
'''
import os
import sys
import zipfile
if __name__ == '__main__':
if len(sys.argv) != 2:
print 'Usage: gbkzip < zipfile.zip >'
exit(1)
try:
zip_obj = zipfile.ZipFile(sys.argv[1], 'r')
except IOError as e:
print e.strerror
exit(1)
for name in zip_obj.namelist():
name_utf8 = name.decode('gb2312')
path = os.path.dirname(name_utf8)
if (not os.path.exists(path)) and path:
os.makedirs(path)
#Start Exacting
filedata = zip_obj.read(name)
if not os.path.exists(name_utf8):
tmp = open(name_utf8, 'w')
tmp.write(filedata)
tmp.close()
print 'Exacting %s ... done!'% (name_utf8)
zip_obj.close()