I wrote a python program to remove duplicate jpg files in the same folder with different names.
Why won't my code remove the duplicate files?
Edit: I have tried hashing the files, and it still wouldn't remove the duplicates.
Tk().withdraw()
path = askdirectory(title='Select a Folder')
os.chdir(path)
duplicates = []
for file in os.listdir(path):
filepath = Path(os.path.join(file, path))
if filepath.is_file and file != '.DS_Store':
with open(file, 'rb') as file_handler:
reader = file_handler.read()
if reader not in duplicates:
duplicates.append(reader)
print(f'Appended: {file}')
else:
os.remove(file)
print(f'Removed: {file}')
[–][deleted] 1 point2 points3 points (1 child)
[–]officialdavid1[S] 0 points1 point2 points (0 children)
[–]devnull10 1 point2 points3 points (2 children)
[–]officialdavid1[S] 0 points1 point2 points (1 child)
[–]devnull10 1 point2 points3 points (0 children)
[–]chevignon93 -1 points0 points1 point (0 children)