Skip to content

Instantly share code, notes, and snippets.

Last active April 8, 2017 14:34
Show Gist options
  • Save nerdtalker/4187084 to your computer and use it in GitHub Desktop.
Save nerdtalker/4187084 to your computer and use it in GitHub Desktop.
EXIFmover - Moves Dropbox Camera uploaded Images into sensible directories
# Name:
# Author: Brian Klug (@nerdtalker /
# Purpose:
# Move Files into directory based on EXIF data make and model
# Designed to un-clusterfuck the Dropbox camera upload directory which is a mess of every
# JPEG and PNG ever if you use it like I do on a bunch of phones, and thus totally unwieldy
# and full of images sorted by date or else nothing sometimes, dropbox seems nondeterminstic
# Moves files into /[Image Make]+[Image Model]/ eg /Camera Uploads/LGE Nexus 4/
# Creates directory if it doesn't exist, moves into that directory if it exists
# Files without EXIF get moved into /nomake nomodel (EG screenshots / nonsense) except exifmover/
# This is experimental and one-way in a destructive sense, I take no responsibility
# if this absolutely destroys your directory structure for some reason
# I STRONGLY recommend making a copy of Camera Uploads, then running this on the copy, first
# Requires EXIF-PY to be installed and importable
# EXIF-PY can be obtained from
# Previous implementation used standalone, updated to work with installable version
# Run simply (eg from ipython "run" inside "Camera Upload")
# Tested on OS 10.8.2 and Python 2.7.3 EPD
# Tested on Windows XP and Python 2.7.3 EPD
# Tested on Ubuntu 11.10
import exifread
print "exifread was not found in the same directory as"
import os
import time
path = os.getcwd()
excludedfiles = ["","","","thumbs.db",".DS_Store","EXIF.pyc"]
for fname in dirList:
if os.path.isfile(fname):
if fname not in excludedfiles:
print "File name is " + fname
f = open(fname)
tags = exifread.process_file(f)
print "Couldn't read tag on " + fname
make = tags['Image Make'].printable
except: make = 'nomake'
model = tags['Image Model'].printable
except: model = 'nomodel'
src = path + "/" + fname
#print "source is " + src
dst = path + "/" + make + " " + model + "/"
#print "destination is " + dst
if os.path.isdir(dst) == False:
#print "made" + dst
destination = dst+fname
print "Oh noes. That didn't work for some reason"
print 'Done. Execution took {:0.3f} seconds'.format((time.time() - start_time))
Copy link

cronburg commented Oct 5, 2013

You need to sanitize the 'Image Make' and 'Image Model' tags - I for instance have images with exif data where model="SAMSUNG ST65 / VLUU ST65 / SAMSUNG ST67". The forward slashes cause os.mkdir() to die (under linux at least).

Copy link

+1 ^

Copy link

vjocw commented Dec 26, 2015

Worked well for me. Thank you for sharing this. Your documentation is really great.

Copy link

Works great! Thank you! 👍

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