My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
YearMonthDayFolders  

Featured
Updated Jul 18, 2011 by kee...@gmail.com

#Copy images to year/month/day folder structure

In response to issue 26 - using chronolapse for long term capture and needing the images sorted into year/month/day folder hierarchy.

Save this as a python script (mine is filestofolders.py). Edit the SOURCEFOLDER, OUTFOLDER, EXTENSION, and PREFIX variables to point to your folder of images, the folder you want as the root of your year/month/day folders, the extension of the image types you used, and the prefix for your images (default is screen). Run with python filestofolders.py.

Please be careful -- double check your paths before you start because this does zero checking before copying everything.

Use at your own risk blah blah blah.

#!usr/bin/python

import os, shutil, time, datetime


SOURCEFOLDER = 'test'
OUTFOLDER = 'out'
EXTENSION = '.jpg'  # extra precaution against processing unwanted files
PREFIX = 'screen_'

for f in os.listdir(SOURCEFOLDER):
    if f.endswith(EXTENSION):
        sourcefile = os.path.join(SOURCEFOLDER, f)

        timestamp = os.path.splitext(f)[0][len(PREFIX):]
        year = timestamp[:4]
        month = timestamp[5:7]
        day = timestamp[8:10]

        outfile = os.path.join(OUTFOLDER, year, month, day, f)

        # make folders as necessary
        try:
          os.makedirs( os.path.dirname(outfile))
        except:
          pass
        # copy it
        shutil.copy(sourcefile, outfile)
Comment by j...@fyrastudio.com, Jul 19, 2011

Chronolapse is not generating the correct timestamps! But the clock in my computer is OK. Im getting screen_1310171380.49.jpg screen_1310171383.66.jpg screen_1310491388.71.jpg for snapshots taken at 2011/07/08 09:29:40, 2011/07/08 09:29:43, 2011/07/08 09:29:46 respectively. So this script is not working as it should, or chronolapse is not working as it should. I'm running on windows 7 64bits. Any ideas?


Sign in to add a comment
Powered by Google Project Hosting