Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A Python Script for tidying up Dropbox's Camera Uploads Folder
import shutil
import os
import re
source = '/Users/jcur002/Dropbox/Camera Uploads/'
files = os.listdir(source)
pat = re.compile(r'^(?P<year>20(0[1-2]|1[2-9]|2[0-1]))\-(?P<month>0[1-9]|1[0-2])\-(?P<day>[0][1-9]|[12][0-9]|3[01])[ -](?P<timestamp>.*)\.(?P<extn>gif|png|jpe*g|mts|mp4|mov)$', re.IGNORECASE)
for f in files:
m = pat.match(f)
if m:
year = m.group('year')
month = m.group('month')
day = m.group('day')
ts = m.group('timestamp')
extn = m.group('extn')
srcFile = os.path.join(source, '{year}-{month}-{day} {ts}.{extn}'.format(year = year,
month = month,
day = day,
ts = ts,
extn = extn))
destFolder = os.path.join(source, year, month)
destFile = os.path.join(destFolder, '{year}-{month}-{day} {ts}.{extn}'.format(year = year,
month = month,
day = day,
ts = ts,
extn = extn))
if not os.path.isdir(destFolder):
os.makedirs(destFolder)
print("Moving: " + srcFile + " to :" + destFile)
shutil.move(srcFile, destFile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment