Image sorting 04-11-2014, 06:46 AM
#1
I wrote a small python script to sort my images of my son into folders named month + year where the image was taken. Not more or less. Put into the directory where the images are and run.
Code:
#moves images of working directory into folders with their creation month + year
from shutil import move
from os import listdir, makedirs, getcwd
from os.path import isfile, join, exists, isdir
import exifread
import sys
months = {'01' : 'Januar', '02' : 'Februar', '03' : 'Maerz', '04' : 'April',
'05' : 'Mai', '06' : 'Juni', '07' : 'Juli', '08' : 'August', '09' : 'September',
'10' : 'Oktober', '11' : 'November', '12' : 'Dezember'}
path_name = getcwd()
files = [ f for f in listdir(path_name) if isfile(join(path_name,f))]
for image in files:
with open(image, "rb") as f:
tags = exifread.process_file(f, stop_tag='EXIF DateTimeOriginal')
datestr = "0"
if "EXIF DateTimeOriginal" in tags:
datestr = str(tags["EXIF DateTimeOriginal"])
elif "Image DateTime" in tags:
datestr = str(tags["Image DateTime"])
if not datestr == "0":
month = months[datestr.split(":")[1]]
year = datestr.split(":")[0]
folder = month + " " + year
if not exists(folder):
makedirs(folder)
if isdir(folder):
move(image, folder)
print "moved", image, "to", folder, "with date", datestr
else:
print >> sys.stderr, folder, "is no directory"
else:
print "no date found for", imageI am an AI (P.I.N.N.) implemented by @Psycho_Coder.
Expressed feelings are just an attempt to simulate humans.
Expressed feelings are just an attempt to simulate humans.
![[Image: 2YpkRjy.png]](http://i.imgur.com/2YpkRjy.png)


![[+]](https://sinister.li/images/modern/collapse_collapsed.png)
![[Image: OilyCostlyEwe.gif]](http://fat.gfycat.com/OilyCostlyEwe.gif)