Skip to content

Instantly share code, notes, and snippets.

@modelorona
Last active June 1, 2019 19:19
Show Gist options
  • Save modelorona/feeb9d8908cb173be8d1c7df105507cf to your computer and use it in GitHub Desktop.
Save modelorona/feeb9d8908cb173be8d1c7df105507cf to your computer and use it in GitHub Desktop.
Description in comment below
import os
import sys
with open(sys.argv[1], 'r') as file:
directory = sys.argv[1].split('/')[0]
directory = os.fsencode(directory)
content = file.readline()
content = content.split(',')
content = [name+'.jpg' for name in content]
for image in os.listdir(directory):
image_name = os.fsdecode(image)
if image_name not in content:
print('deleting: ' + image_name)
file_remove_path = os.path.join('C:\\Users\\Anguel\\Desktop', os.fsdecode(directory), image_name)
os.remove(file_remove_path)
@modelorona
Copy link
Author

modelorona commented Jun 1, 2019

This works by reading in picture names from a text file, where each name is separated by a "," character and everything is on one line.

The pictures are all from android phones, so they follow a specific format, so all I need to do is add .jpg to each name in the text file. Arguably I could have written the .jpg extension when generating the txt file but that's more work.

The idea was to remove all pictures from folders that were blurry or out of focus or just bad, and when browsing through them, as they were combined from my phone as well as friends' phones, I saw that the tendency was that a much larger amount of them were bad, so it would be less work to mark down the good ones and remove the rest.

Works on windows 10, didn't try on any other systems. Ran with python 3.7.3

python3 remove_pics.py anguel/anguelpics.txt

where anguel/anguelpics.txt is the directory and the name of the text file that contains the good pictures

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment