forked from PeterDing/iScript
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathunzip.py
executable file
·37 lines (32 loc) · 853 Bytes
/
unzip.py
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
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import os
import sys
import zipfile
print "Processing File " + sys.argv[1]
file = ''
if len(sys.argv) == 3:
file=zipfile.ZipFile(sys.argv[1],"r")
file.setpassword(sys.argv[2])
else:
file=zipfile.ZipFile(sys.argv[1],"r")
for name in file.namelist():
try:
utf8name=name.decode('gbk')
pathname = os.path.dirname(utf8name)
except:
utf8name=name
pathname = os.path.dirname(utf8name)
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):
try:
fo = open(utf8name, "w")
fo.write(data)
fo.close
except:
pass
file.close()