Created
February 1, 2016 11:46
-
-
Save icedraco/facf9031d6eec35b079a to your computer and use it in GitHub Desktop.
Sort a crapload of JPEG files from lectures into folders by date
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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