Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ebinnion
Forked from diegodukao/dropboxOrganize.py
Created June 29, 2018 00:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ebinnion/ce0168ab20057e2b2b07da9e0ac7ee68 to your computer and use it in GitHub Desktop.
Save ebinnion/ce0168ab20057e2b2b07da9e0ac7ee68 to your computer and use it in GitHub Desktop.
################################################################################################
#
# 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