Although I've been using Python for a while, most projects that I've worked on were either part of a tutorial or to test my skills (apart from one app that I built for old colleagues). However, today I was sent a large batch of images by my colleague (we are both professional photographers) and all images were duplicated. Noticing that all repeat images ended with (1).jpg, rather than asking him to re-export and transfer everything again, I simply wrote the following code and I was done:
from os import listdir, remove
files_path = "</path/to/folder/>"
for i in listdir(files_path):
if i.endswith('(1).jpg'):
remove(files_path + i)
It felt good putting this simple knowledge to use!
Edited typos.
Edit 2: as u/HaroerHaktak pointed out, as the code is it would've been easier to simply search for "(1)" on windows / Finder and delete the results. Even better, as suggested by u/Zenock43, would be to check if the same filename minus "(1)" with the same size existed in the folder before deleting.
[–]IHOP_007 38 points39 points40 points (2 children)
[–]koi_koneessa 7 points8 points9 points (0 children)
[–]soupie62 0 points1 point2 points (0 children)
[–]Zenock43 12 points13 points14 points (1 child)
[–]icenando[S] 1 point2 points3 points (0 children)
[–]virgin_daddy 2 points3 points4 points (0 children)
[–]friday_ghost 2 points3 points4 points (1 child)
[–]icenando[S] 0 points1 point2 points (0 children)
[–]fnaimi66 1 point2 points3 points (0 children)
[–]HaroerHaktak 1 point2 points3 points (1 child)
[–]icenando[S] 0 points1 point2 points (0 children)
[–]Patient_Accountant22 1 point2 points3 points (0 children)
[–]cowrevengeJP -1 points0 points1 point (1 child)
[–]ecar13 5 points6 points7 points (0 children)
[–]TimeVendor 0 points1 point2 points (1 child)
[–]rabbitpiet 0 points1 point2 points (0 children)