title: Find and remove duplicate files using Python
body: <p>I have several folders which contain duplicate files that have slightly different names (e.g. file_abc.jpg, file_abc(1).jpg), or a suffix with "(1) on the end. I am trying to develop a relative simple method to search through a folder, identify duplicates, and then delete them. The criteria for a duplicate is "(1)" at the end of file, so long as the original also exists.</p>
  
  <p>I can identify duplicate okay, however I am having trouble creating the text string in the right format to delete them. It needs to be <code>"C:\Data\temp\file_abc(1).jpg"</code>, however using the code below I end up with <code>r"C:\Data\temp''file_abc(1).jpg"</code>.</p>
  
  <p>I have looked at answers [<a href="https://stackoverflow.com/questions/748675/finding-duplicate-files-and-removing-them][1]">Finding duplicate files and removing them</a>, however this seems to be far more sophisticated than what I need.</p>
  
  <p>If there are better (+simple) ways to do this then I let me know, however I only have around 10,000 files in total in 50 odd folders, so not a great deal of data to crunch through.</p>
  
  <p>My code so far is:</p>
  
  <pre><code>import os
  
  file_path = r"C:\Data\temp"
  file_list = os.listdir(file_path)
  print (file_list)
  
  for file in file_list:
      if ("(1)" in file):
      index_no = file_list.index(file)
      print("!! Duplicate file, number in list: "+str(file_list.index(file)))
      file_remove = ('r"%s' %file_path+"'\'"+file+'"')
      print ("The text string is: " + file_remove)
      os.remove(file_remove)
  </code></pre>