Created
March 18, 2017 00:12
-
-
Save luisfcorreia/177eaf08c3496c2f37bd6cc3796b299c to your computer and use it in GitHub Desktop.
This file contains 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
import os, time | |
import glob | |
#get current Folder | |
folder = os.getcwd()+'/' | |
print 'Using pictures from ' + folder | |
fileFormats = ['JPG','jpg', 'MOV', 'mov', 'PNG', 'png', 'mp4', 'MP4', '3gp', 'jpeg']; | |
months = ['January','February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] | |
picPath = [] | |
#Generate list of files | |
for formats in fileFormats: | |
picPath = picPath + glob.glob(folder + "*."+formats) | |
for files in picPath: | |
picName = files.split('\\') | |
filename = picName[-1][:-4].split(' ') | |
date = filename[len(filename)-2].split('_') | |
dateYear = date[1][:4] | |
dateMonth = date[1][4:6] | |
#folder exists? if not, create them! | |
if not os.path.exists(folder + dateYear): | |
print 'Making dir:' + folder + dateYear | |
os.makedirs(folder + dateYear) | |
finalFolder = folder + dateYear + '/' + dateMonth | |
if not os.path.exists(finalFolder): | |
print 'Making dir:' + finalFolder | |
os.makedirs(finalFolder) | |
#Move files | |
print 'Moving: ' + files + ' --> ' + finalFolder + '/' #+ picName[-1] | |
print os.path.basename(files) | |
os.rename(files,finalFolder + '/' +os.path.basename(files)) | |
print "Completed!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment