-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunzip.py
More file actions
90 lines (68 loc) · 2.22 KB
/
unzip.py
File metadata and controls
90 lines (68 loc) · 2.22 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import zipfile
import rarfile
from os import path
import os
rarfile.UNRAR_TOOL = "UnRAR.exe"
files = []
errors = []
def FileExist(location):
ext = path.splitext(location)[1]
if ext == ".rar" or ext == ".zip":
files.append(location)
def UnzipFile(fileName):
ext = path.splitext(fileName)[1]
if ext == '.zip':
try:
createFolder(fileName)
with zipfile.ZipFile(compressPath + '\\' + fileName, 'r') as zip_ref:
zip_ref.extractall(os.getcwd())
os.chdir(compressPath + '\\Unzip')
print("Zip", fileName)
except:
errors.append(fileName)
os.chdir(compressPath + '\\Unzip')
print("Error", fileName)
elif ext == '.rar':
try:
createFolder(fileName)
with rarfile.RarFile(compressPath + '\\' + fileName, 'r') as rar_ref:
rar_ref.extractall(os.getcwd())
os.chdir(compressPath + '\\Unzip')
print("Rar", fileName)
except:
errors.append(fileName)
os.chdir(compressPath + '\\Unzip')
print("Error", fileName)
else:
print("None")
def createFolder(fileName):
dir = path.join(path.abspath('')) + '\\' + fileName
if not os.path.exists(dir):
os.mkdir(dir)
else:
print('Existed', fileName)
os.chdir(dir)
def main():
compressPath = path.abspath('..')
tmpFiles = os.listdir(compressPath)
for myFile in tmpFiles:
FileExist(myFile)
return compressPath
# for nFile in files:
# UnzipFile(nFile, compressPath)
compressPath = main()
print(len(files))
for nFile in files:
UnzipFile(nFile)
print("Errors", errors)
# UnzipFile("00-main-files_NWExYjA0Y2U3YTQ4NWQwMDNkOGU2ZDNh.zip")
# UnzipFile("Carnaval Flat Illustration Set.rar")
# createFolder('Hello')
# try:
# createFolder("Hello")
# with rarfile.RarFile("d:\\ui8" + "\\Carnaval Flat Illustration Set.rar", 'r') as rar_ref:
# rar_ref.extractall(os.getcwd())
# with zipfile.ZipFile("d:\\ui8" + "\\cobank-banking-finance-and-crypto-wallet-app-ui-kit_NWExYjA0Y2U3YTQ4NWQwMDNkOGU2ZDNh.zip", 'r') as zip_ref:
# zip_ref.extractall(os.getcwd())
# except:
# print("Error")