import os FOLDER1="/location/to/folder1" #do not use trailing slash for either folder FOLDER2="/location/to/folder2" # the matching files are removed from this folder blah = os.popen("ls %s"% (FOLDER1)) blah = blah.readlines() blah2 = os.popen("ls %s"% (FOLDER2)) blah2 = blah2.readlines() for line in blah: line = line.replace("\n", "", 1) for line2 in blah2: line2 = line2.replace("\n", "", 1) if line == line2: print "%s = %s - deleting"% (line, line2) os.popen("rm %s/%s"% (FOLDER2, line2))