File tree Expand file tree Collapse file tree 4 files changed +32
-0
lines changed
Python/remove_duplicate_files Expand file tree Collapse file tree 4 files changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Remove duplicate files from directory
2
+ - - - - - - - - - - - - -
3
+ ## Aim
4
+ Aim of the script is to remove duplicate files from a directory.
5
+
6
+ ## To run
7
+ - Run ``` remove.py ```
8
+ - Enter the path to the directory or sub-directory in which you want to delete duplicate files</br >
9
+
10
+ ## Example
11
+ The current directory contains ``` file1.txt ``` and ``` file2.txt ``` that have the same contents. </br >
12
+ Running ``` remove.py ``` will remove ``` file2.txt ``` as it is a duplicate of file1.txt
Original file line number Diff line number Diff line change
1
+ This file is for testing
Original file line number Diff line number Diff line change
1
+ This file is for testing
Original file line number Diff line number Diff line change
1
+ # python program to remove duplicate files from directory
2
+ import os
3
+ import hashlib
4
+ import glob
5
+ #taking path of directory as user input
6
+ PATH_directory = input ("Please enter the path of directory in which you wish to remove duplicate files : " )
7
+ unique_files = []
8
+ for file in os .listdir (PATH_directory ):
9
+ # checking if path is existing file
10
+ if os .path .isfile (file ):
11
+ hash = hashlib .md5 (open (file , 'rb' ).read ()).hexdigest ()
12
+ # if hash of the file in consideration is unique
13
+ if hash not in unique_files :
14
+ unique_files .append (hash )
15
+ # delete file if it has a matching hash
16
+ else :
17
+ print ("Found a duplicate. Now removing duplicate file" )
18
+ os .remove (file )
You can’t perform that action at this time.
0 commit comments