Script to Organize Dropbox’s Camera Upload folder

Dropbox has a great feature called Camera Upload, where you can automatically upload pictures from your phone, making life for lazy people like me easier. The problem is that I take so many pictures with my phone that the folder ends up with a huge amount of files, making the task of browsing and viewing them slow and annoying.

To fix this problem, I created a python script that will automatically organize pictures inside folders Year > Month.

DropboxCameraUpload

How to use:

In order to use the script, put the file organize.py inside the ‘Camera Upload’ folder and run it from the terminal:

python organize.py

Enjoy!

Code:

😉

3 Comments Add yours
  1. Thanks heaps…
    I have updated to allows for different file name and more formats. i.e. _yyyymmdd_hour., _yyyy-mm-dd_hour., yyyy-mm-dd hour. etc…
    It also uses the modified date if it is unable to derive it from the name. Changed the folder structure to work with windows:
    ################################################################################################
    #
    # Script to organize pictures uploaded from Mobile Devices to Dropbox’s Camera Upload folder
    #
    # Daniel Spillere Andrade – https://www.danielandrade.net
    #
    ################################################################################################

    # Supported files _yyyymmdd_hour., _yyyy-mm-dd_hour., yyyy-mm-dd hour.

    import os, time
    import glob
    import datetime
    #Return lengths in string
    def chunkstring(string, length):
    return (string[0+i:length+i] for i in range(0, len(string), length))

    #Define Pictures Folder
    #You will have to change this!
    folder = ”

    fileFormats = [‘JPG’,’jpg’, ‘jpeg’, ‘JPEG’, ‘MOV’, ‘mov’, ‘PNG’, ‘png’, ‘mp4’, ‘MP4’, ‘3gp’, ‘3GP’, ‘gif’, ‘GIF’]
    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)
    picPath = list(set(picPath))

    for files in picPath:
    print (“”)
    try:
    picName = files.split(‘\\’)

    if “_” in picName[-1][:-4]:
    filename = picName[-1][:-4].split(‘_’)
    else:
    filename = picName[-1][:-4].split(‘ ‘)

    if len(filename)>=3:
    filestart = 1
    else:
    filestart = 0

    try:
    if “-” in filename[filestart]:
    date = filename[filestart].split(‘-‘)
    dateYear = date[0]
    dateMonth = date[1]
    dateDay = date[2]
    else:
    date = list(chunkstring(filename[filestart], 2))
    dateYear = date[0]+date[1]
    dateMonth = date[2]
    dateDay = date[3]
    if not (len(dateYear) is 4 and len(dateMonth) is 2 and 1<=int(dateMonth) ‘ + folder + dateYear + ‘\\’ + monthNum + ‘-‘ + month + ‘\\’)
    os.rename(picName[-1],folder + dateYear + ‘\\’ + monthNum + ‘-‘ + month + ‘\\’ + picName[-1])
    except:
    print (“Couldn’t sort: “+files)
    continue
    print (“\nDone :)”)

Leave a Reply

Your email address will not be published. Required fields are marked *