Skip to content

Commit 3194b08

Browse files
authored
Merge pull request larymak#76 from mas-designs/main
Added Project (Removal of Duplicate Files)
2 parents d4523eb + 0136666 commit 3194b08

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,4 @@ The contribution guidelines are as per the guide [HERE](https://github.com/larym
8585
| 42 | [Geocoding Google API](https://github.com/Mannuel25/Python-project-Scripts/tree/main/Geocoding%20Google%20API) | [Sherief Elsowiny](https://github.com/elsowiny) |
8686
| 43 | [News Article Scraping](https://github.com/Mannuel25/Python-project-Scripts/tree/main/News_Article_Scraping) | [SasiKalyan](https://github.com/KanakamSasikalyan) |
8787
| 44 | [Sudoku Solver](https://github.com/Mannuel25/Python-project-Scripts/tree/main/SudokuSolver) | [Ruben Grande Muñoz](https://github.com/RgrMz) |
88+
| 45 | [Duplicate File Remover](https://github.com/mas-designs/Python-project-Scripts/tree/main/Remove%20Duplicate%20Files%20in%20Folder) | [Michael Stadler](https://github.com/mas-designs) |
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)