-
-
Save diegodukao/7b3004867498795b139b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################################################ | |
# | |
# 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 | |
folder = '/Your/Dropbox/Camera Uploads/folder/path/' | |
print 'Finding pictures from ' + folder | |
fileFormats = ['JPG','jpg', 'MOV', 'mov', 'PNG', 'png', 'mp4', 'MP4', '3gp', 'jpeg']; | |
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('-') | |
# if there is any filename different of the pattern of the dropbox pictures | |
# filename[1] is index out of range | |
try: | |
hour = filename[1] | |
except: | |
continue | |
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 :)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment