Skip to content

Instantly share code, notes, and snippets.

@wildintellect
Last active August 29, 2015 14:06
Show Gist options
  • Save wildintellect/3c3595cff9472dc546c2 to your computer and use it in GitHub Desktop.
Save wildintellect/3c3595cff9472dc546c2 to your computer and use it in GitHub Desktop.
Sorts bracketed photos into 3 subfolders
#!/usr/bin/env python
# -*- coding: utf_8 -*
#
# Script to sort bracketed photos by exposure into bins.
# Default assumes 3 photos per bracket set, into 3 folders
#
# Alex Mandel 2014
# [email protected]
# requires python
import os
import shutil
#assumes current directory has the photos
def photolist(directory):
'''get list of photos in the directory'''
#TODO: support raw file sorting too instead and in addition to jpg
extension = ".jpg"
list_of_files = [file for file in os.listdir(directory) if file.lower().endswith(extension)]
return(list_of_files)
def makefolders(fold):
#TODO: take an arbitrary number of folders to sort
[os.mkdir(name) for name in fold if not os.path.exists(name)]
return
def sort(plist,fold):
'''sort the photos'''
#The 1st photo in the set to base the sorting off
#If it ever gets up to 9999 on the photo number this will all break
start = int(plist[0][4:8])
for item in plist:
#sort the photos, awesome idea from ntw @ LUGOD
#modulo is by length of folder list
f = ((int(item[4:8])-start) % len(fold))
shutil.move(item, fold[f])
return
if __name__ == '__main__':
#TODO: take command line parameters
directory = os.curdir
fold = ["one","two","three"]
try:
os.chdir(directory)
photos = photolist(directory)
makefolders(fold)
sort(photos, fold)
except Exception as e:
print(" ".join(["Something failed because of",str(e)]))
#finally:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment