File tree 2 files changed +29
-0
lines changed
Remove Duplicate Files in Folder
2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -85,3 +85,4 @@ The contribution guidelines are as per the guide [HERE](https://github.com/larym
85
85
| 42 | [ Geocoding Google API] ( https://github.com/Mannuel25/Python-project-Scripts/tree/main/Geocoding%20Google%20API ) | [ Sherief Elsowiny] ( https://github.com/elsowiny ) |
86
86
| 43 | [ News Article Scraping] ( https://github.com/Mannuel25/Python-project-Scripts/tree/main/News_Article_Scraping ) | [ SasiKalyan] ( https://github.com/KanakamSasikalyan ) |
87
87
| 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 number Diff line number Diff line change
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" )
You can’t perform that action at this time.
0 commit comments