Skip to content

Instantly share code, notes, and snippets.

@dansku
Created February 16, 2014 20:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save dansku/9040240 to your computer and use it in GitHub Desktop.
Save dansku/9040240 to your computer and use it in GitHub Desktop.
Script to organize pictures uploaded from Mobile Devices to Dropbox's Camera Upload folder
################################################################################################
#
# Script to organize pictures uploaded from Mobile Devices to Dropbox's Camera Upload folder
#
# Daniel Spillere Andrade - www.danielandrade.net
#
################################################################################################
import os, time
import glob
#Define Pictures Folder
#You may have to change this!
folder = '/Users/admin/Dropbox/Camera Uploads/'
fileFormats = ['JPG','jpg', 'MOV', 'mov', 'PNG', 'png', 'mp4', 'MP4'];
months = ['January','February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
picPath = []
#Generate list of files
for formats in fileFormats:
picPath = picPath + glob.glob(folder + "*."+formats)
for files in picPath:
picName = files.split('/')
filename = picName[-1][:-4].split(' ')
date = filename[0].split('-')
hour = filename[1]
dateYear = date[0]
dateMonth = date[1]
dateDay = date[2]
month = months[int(dateMonth)-1]
monthNum = str(int(dateMonth)).zfill(2)
#folder exists? if not, create them!
if not os.path.exists(folder + dateYear):
print 'Making dir:' + folder + dateYear
os.makedirs(folder + dateYear)
if not os.path.exists(folder + dateYear + '/' + monthNum + '-' + month):
print 'Making dir:' + folder + dateYear + '/' + monthNum + '-' + month
os.makedirs(folder + dateYear + '/' + monthNum + '-' +month)
#Move files
print 'Movendo: ' + files + ' --> ' + folder + dateYear + '/' + monthNum + '-' + month + '/'
os.rename(picName[-1],folder + dateYear + '/' + monthNum + '-' + month + '/' + picName[-1])
print "Done :)"
@diegodukao
Copy link

Hey man. Thanks for the script.
I had an error running it in my Camera Uploads because I had some pictures with filenames out of the pattern of the folder. I have updated the code: https://gist.github.com/diegodukao/7b3004867498795b139b

Abraço

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