-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathduplicate_file_remover.py
54 lines (50 loc) · 1.37 KB
/
duplicate_file_remover.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import os
import sys
#List files and sizes
file_names = (os.listdir())
file_sizes = []
for i in file_names:
file_sizes.append(os.stat(i).st_size)
listgeneral = list()
value = 0
while value < len(file_names) :
listgeneral.append(file_names[value])
listgeneral.append(file_sizes[value])
value += 1
# add for delete
all_cluster = set()
value2 = 0
while value2 < len(file_names)-1 :
for i in file_sizes:
if file_sizes.count(i) > 1:
all_cluster.add(i)
value2 += 1
all_cluster2 = list(all_cluster)
#Duplicate
value3 = 0
value4 = 0
delete_place = []
while value3 < len(all_cluster2):
while value4 < (listgeneral.count(all_cluster2[value3])-1):
value4 += 1
delete_place.append((all_cluster2[value3]))
if value4 == (listgeneral.count(all_cluster2[value3])-1):
value4 = 0
value3 += 1
#ASK
if len(delete_place) < 1:
print ("There is no duplicate.")
sys.exit()
else:
print (len(delete_place) , "files will be delete. Are you sure ? Y|N")
eminmisin = input ("")
if eminmisin == "n" or eminmisin == "N":
print ("Exit")
sys.exit()
else:
#delete
for i in delete_place:
if i in listgeneral:
os.remove(listgeneral[listgeneral.index(i)-1])
listgeneral.pop(listgeneral.index(i)-1)
listgeneral.pop(listgeneral.index(i))