-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunzip.py
More file actions
107 lines (84 loc) · 2.94 KB
/
Copy pathunzip.py
File metadata and controls
107 lines (84 loc) · 2.94 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import os
from pickle import GLOBAL
import zipfile39 as zipfile
import rarfile
import py7zr
import glob
from tqdm import tqdm
import numpy as np
global err_file_list
err_file_list = []
def un_zip(file_name):
try:
zip_file = zipfile.ZipFile(file_name)
os.makedirs(file_name + '_extract')
zip_file.extractall(file_name + '_extract')
zip_file.close()
except:
err_file_list.append(file_name)
def un_rar(file_name):
try:
rar_file = rarfile.RarFile(file_name)
os.makedirs(file_name + '_extract')
rar_file.extractall(file_name + '_extract')
rar_file.close()
except:
err_file_list.append(file_name)
def un_7z(file_name):
try:
z7_file = py7zr.SevenZipFile(file_name)
os.makedirs(file_name + '_extract')
z7_file.extractall(file_name + '_extract')
z7_file.close()
except:
err_file_list.append(file_name)
# zip_file = "test/porsche-718-cayman-gt4-2020.zip"
# un_zip(zip_file)
# z7_file = "test/Mercedes-Benz C-Class 2019.7z"
# un_7z(z7_file)
# rar_file = "test/Car Porsche 911 Carrera Cabriolet 2019.rar"
# un_rar(rar_file)
dict_dir = os.walk('.')
# for dirpath, dirnames, filenames in os.walk('.'):
# for dirname in dirnames:
# print(os.path.join(dirpath, dirname))
# for dirpath, dirnames, filenames in os.walk('.'):
# for filename in filenames:
# print(os.path.join(dirpath, filename))
zip_file_list = []
rar_file_list = []
z7_file_list = []
for dirpath, dirnames, filenames in dict_dir:
for dirname in dirnames:
dir_path = os.path.join(dirpath, dirname)
zip_file_list += glob.glob(os.path.join(dir_path, "*.zip"))
rar_file_list += glob.glob(os.path.join(dir_path, "*.rar"))
z7_file_list += glob.glob(os.path.join(dir_path, "*.7z"))
print("%d .zip files found" %(len(zip_file_list)))
for i in tqdm(range(len(zip_file_list)), desc = "extracting .zip files"):
if os.path.exists(zip_file_list[i] + "_extract"):
print("%s already extracted" %(zip_file_list[i]))
else:
print(zip_file_list[i])
un_zip(zip_file_list[i])
os.system(r"clear")
print("%d .rar files found" %(len(rar_file_list)))
for i in tqdm(range(len(rar_file_list)), desc = "extracting .rar files"):
if os.path.exists(rar_file_list[i] + "_extract"):
print("%s already extracted" %(rar_file_list[i]))
else:
print(rar_file_list[i])
un_rar(rar_file_list[i])
os.system(r"clear")
print("%d .7z files found" %(len(z7_file_list)))
for i in tqdm(range(len(z7_file_list)), desc = "extracting .7z files"):
if os.path.exists(z7_file_list[i] + "_extract"):
print("%s already extracted" %(z7_file_list[i]))
else:
print(z7_file_list[i])
un_rar(z7_file_list[i])
os.system(r"clear")
# np.savetxt("err_list.txt", np.array(err_file_list))
with open("err_list.txt", "w") as f:
strs = '\n'
f.write(strs.join(err_file_list))