-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusing_7z.py
More file actions
136 lines (111 loc) · 4.74 KB
/
using_7z.py
File metadata and controls
136 lines (111 loc) · 4.74 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import os
import patoolib
class extract_using_7z:
def __init__(self):
self.basepath = "E:/Courses Drive/"
self.outpath = "D:/ELITE Club/"
def _find_first_file(self, dir_lst):
file_size = []
first_file = None
if len(dir_lst) == 1:
return dir_lst[0]
else:
for d in dir_lst:
self._file_path = os.path.join(self._dir_path, d)
extension = d.split(".")
last = extension[-2]
if extension[-2] == 'part1' or extension[-2] == 'part01':
# This will return file with contain part1
first_file = d
break
elif extension[-1] == 'ini':
# This will remove file with extension .ini
try:
os.remove(self._file_path)
except Exception as e:
print(e)
elif len(extension[-2]) > 6:
# Give file name is minimum length
file_size.append(os.path.getsize(self._file_path))
if len(file_size) == 0:
pass
else:
minimum_length = max(file_size)
first_file = dir_lst[file_size.index(minimum_length)]
return first_file
def multi_file(self):
# f = open(self.outpath + '/fileList.txt', "w") # 'r' for reading and 'w' for writing
for entry in os.listdir(self.basepath):
self._dir_path = os.path.join(self.basepath, entry)
if os.path.isdir(self._dir_path):
dir_file_list = os.listdir(self._dir_path)
self._first_file = self._find_first_file(dir_file_list)
first_file_path = self._dir_path + '/' + self._first_file
# f.write(first_file_path + ',') # Write inside file
try:
patoolib.extract_archive(first_file_path, pwd="@FTUCHAT", outdir=self.outpath)
except Exception as e:
print('File: {} Error: {}'.format(self._first_file, e))
print(e)
# f.close()
class match_dir:
def __init__(self):
self.mainpath = "D:/Users/Sachin/Google Drive/Study/Stock/ELITE CLUB/101-200 Courses FTU ELITE/"
self.basepath = "E:/Courses Drive/"
self.main_files_lst = [x for x in os.listdir(self.mainpath)]
self.base_files_lst = [x for x in os.listdir(self.basepath)]
def match_size(self):
counter = 0
for i in self.main_files_lst:
b_file = self.base_files_lst[counter]
m_file_path = os.path.join(self.mainpath, i)
b_file_path = os.path.join(self.basepath, b_file)
if os.path.getsize(m_file_path) == os.path.getsize(b_file_path):
print("True: ", b_file)
else:
print('False: ', b_file)
counter = counter + 1
def del_rar(self):
counter = 0
try:
for i in self.main_files_lst:
subpath = os.path.join(self.mainpath, i)
sub_files_lst = [x for x in os.listdir(subpath)]
if os.path.isdir(subpath):
for s in sub_files_lst:
file_path = os.path.join(subpath, s)
filename, file_extension = os.path.split(file_path)
extension = s.split(".")[-1]
if extension == 'rar' or extension == 'ini':
os.remove(file_path)
counter = counter + 1
else:
print(False)
main_file_path = os.path.join(self.mainpath, i)
extension = i.split(".")[-1]
if extension == 'rar' or extension == 'ini':
os.remove(main_file_path)
counter = counter + 1
# print('filename: {} \n extancen {}'.format(filename, exename))
except NotADirectoryError as e:
print(e)
print('\nCounter: ', counter)
def match_name(self):
counter = 0
for i in self.main_files_lst:
b_file = self.base_files_lst[counter]
print(os.path.join(self.mainpath, i))
if i == b_file:
pass
else:
diff = []
for s in range(len(i)):
if i[s] == b_file[s]:
pass
else:
diff.append(i[s])
print('False: {} -- {}'.format(i, diff))
counter = counter + 1
if __name__ == '__main__' :
f = extract_using_7z()
f.multi_file()