File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
Remove Duplicate Files in Folder Expand file tree Collapse file tree 1 file changed +28
-0
lines changed 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