Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 87937b9

Browse files
msms
authored andcommittedOct 2, 2021
added removal of duplicate files script to project
1 parent 3c25885 commit 87937b9

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
 
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from tkinter import Tk
2+
from tkinter.filedialog import askdirectory
3+
import os, hashlib
4+
from pathlib import Path
5+
6+
7+
Tk().withdraw() # to hide the small tk window
8+
path = askdirectory(title='Select Folder') # shows dialog box and return the path
9+
10+
files_list = os.listdir(path) # take all the filename as a list
11+
12+
unique = dict() # making a dictionary named unique
13+
14+
for file in os.listdir(path): # looping over the file list
15+
16+
file_name = Path(os.path.join(path, file)) # make a absolute file name using os.path.join function
17+
if file_name.is_file(): # checking the the the item is file or not
18+
19+
fileHash = hashlib.md5(open(file_name, 'rb').read()).hexdigest()
20+
if fileHash not in unique:
21+
unique[fileHash] = file_name
22+
23+
else:
24+
print(file_name)
25+
os.remove(file_name)
26+
print(f" File will be deleted {file_name}")
27+
else:
28+
print("Path not exits")

0 commit comments

Comments
 (0)