Skip to content

Instantly share code, notes, and snippets.

@icedraco
Created February 1, 2016 11:46
Show Gist options
  • Select an option

  • Save icedraco/facf9031d6eec35b079a to your computer and use it in GitHub Desktop.

Select an option

Save icedraco/facf9031d6eec35b079a to your computer and use it in GitHub Desktop.
Sort a crapload of JPEG files from lectures into folders by date
from glob import glob
import os
# Extract the date (YYYY-MM-DD) part of the filename
def get_date(filename):
return filename.split(' ')[0]
# Obtain a list of all .jpg files in the current dir
# File format: "YYYY-MM-DD HH.mm.ss.jpg"
files = glob('*.jpg')
# Obtain all the dates we should create folders for
folders = set(map(get_date, files))
# Create all relevant date folders
map(os.mkdir, folders)
# Move all JPEGs to their respective date folders
map(lambda fname: os.rename(fname, "%s/%s" % (get_date(fname), fname), files)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment