-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemove.py
More file actions
62 lines (45 loc) · 2.16 KB
/
Remove.py
File metadata and controls
62 lines (45 loc) · 2.16 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
import threading
import os
import filecmp
class Remove(threading.Thread):
def __init__(self, massage, filename, fullfilename, directory_path, aLabel):
threading.Thread.__init__(self)
self.massage = massage
self.filename, self.file_extension = os.path.splitext(filename)
self.fullfilename = fullfilename
self.directory_path = directory_path
self.count = 0
self.aLabel = aLabel
def run(self):
filepaths = os.listdir(self.massage)
for filepath in list(filepaths):
os.chdir(self.massage)
if(os.getcwd() != self.directory_path): # make sure that we will not delete the same file in the selected file directory
if(os.path.isfile(filepath)):
filename, file_extension = os.path.splitext(filepath)
self.remove_file(file_extension, filepath)
else:
self.delete_duplicate(os.path.join(self.massage, filepath))
else:
continue
if(self.count > 0):
self.aLabel.message = 'Removed ' + str(self.count) + ' duplicate : ' + self.filename # show this message box each time a set of duplicate files have been removed
else:
self.aLabel.message = "No duplicate file found : " + self.filename
def delete_duplicate(self, folder): # sub method to pass folder to
filepaths = os.listdir(folder)
for filepath in list(filepaths):
os.chdir(folder)
if(os.getcwd() != self.directory_path):
if(os.path.isfile(filepath)):
filename, file_extension = os.path.splitext(filepath)
self.remove_file(file_extension, filepath)
else:
self.delete_duplicate(os.path.join(folder, filepath))
else:
continue
def remove_file(self, file_extension, filepath):
if (file_extension == self.file_extension):
if filecmp.cmp(filepath, self.fullfilename, shallow=False):
os.remove(filepath)
self.count += 1