Skip to content

Instantly share code, notes, and snippets.

@jmcurran
Last active May 19, 2021 01:16
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 jmcurran/6f56565fedad44218f21493a826c1762 to your computer and use it in GitHub Desktop.
Save jmcurran/6f56565fedad44218f21493a826c1762 to your computer and use it in GitHub Desktop.
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