Script to sort files by creation date


I have tons of family picture files in png/jpg format that I want to sort.  Using a script on the mac I want the script to traverse a given directory structure and moving all files into another path which is a flat directory with only folders with newly moved files, in the folder format name of YYYY MM DD

Source folder:  /users/<myname>/pictures/picstosort
(This is a folder full of other folders and pics in the root of this folder that needs to be traversed fully)

Destination folder: /users/<myname>/pictures/library
(Folders in here are in the format YYYY MM DD)

Can anyone write this script for me, i don't have a clue how to do this?

Is this even possible!

Who is Participating?
ozoConnect With a Mentor Commented:
perl -MPOSIX -e 'for(<~/pictures/picstosort/*>){ $d=strftime "library/%Y %M %d",localtime((stat)[9]); ($f=$_)=~s/picstosort/$d/; rename $_,$f or warn "$_  $f  $!" }'
Gerwin Jansen, EE MVETopic Advisor Commented:
Hi, I'm probably not able to help you out but:

- Do the file names have date/time info in them as well or is just the timestamp basis for sorting?
- Which scripting language do you suggest experts use the solve your question?
TheDadCoderAuthor Commented:
Hi gerwinjansen, thanks for the response.

I'm not concerned about which scripting lang is used, the result is what i need :)

in terms of your first question, the filename itself can't be used it's just all random filenaming.   I was hoping the script would make use of the meta data of the file, i.e. the Created date.

Is this possible?
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

TheDadCoderAuthor Commented:
Hi ozo,

Does this search by meta data if the picture taken date? Or just the file?
It uses the time of last data modification timestamp.
Did you want to use something else?
TheDadCoderAuthor Commented:
Hi, reviewing a sample of the 100,000 image files that I have, some have an inaccurate date time for the modified date.

So these would need to use the camera's meta data instead. If no meta exists, then to use the last modified date.

Is that possible?
Do you have a script to extract the camera's meta data that my script can call?
Or do you have a specification of how the metadata is stored so I can write a routine to extract it?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.