how to remove duplicate files from folder with python

Solutions on MaxInterview for how to remove duplicate files from folder with python by the best coders in the world

showing results for - "how to remove duplicate files from folder with python"
Emily
14 Jan 2017
1def remove_duplicates(dir):
2    unique = []
3    for filename in os.listdir(dir):
4        if os.path.isfile(filename):
5            filehash = md5.md5(file(filename).read()).hexdigest()
6            if filehash not in unique: 
7                unique.append(filehash)
8            else: 
9                os.remove(filename)
10