May 15, 2010

A Ruby Script to Organize Digital Photos in to a Folder Hierarchy by Date/Time Taken

Filed under: Uncategorized — Tags: , — yasi8h @ 5:26 pm

So i was at home with nothing else to do. I had my new “NAT” with plenty of empty space and my collection of photos. Although when viewing with Picasa there photos were browse-able, when viewing it through a file explorer like nautilus, It was very hard browse them. So i wanted to organize them in to a folder structure that makes some sense. And this is what i came up with. Hope it will be of some use to someone.

Copies digital photos to a directory structure orgnazied by year/month/day/time.ext...etc

Folder Structure

Get it from github:

Photo Organiser

A Ruby script to copy and arrange your digital photos to a folder structure like /Root/Year/Month/Day/Time.jpg … It will use EXIF timestamp if its there or else take file creation timestamp.


    bash> ruby photo_org.rb /path/to/source /path/to/destination dirs


  • Get the source.
  • Install exifr (gem install exifr) if you don’t have them already.


  • If there are two or more files with the same timestamp they will be copied as: file_name.jpg, file_name-1.jpg, file-name-2.jpg…etc
  • Duplicates will be copied to /path/to/dest/Duplicates
  • Non jpeg files will be copied to /path/to/dest/Other
  • The script creates a log file in the destination directory at the end of execution.
  • You can edit more settings like folder names, folder structure, file name…etc by editing the constants inside the script
  • Any feedback will be highly appreciated.



  1. I’d like to see it (or DigiKam or F-Spot) work like Canon’s Zoombrowser: create folder structure and get the picts & vids:

    Comment by Mikko — August 17, 2010 @ 5:42 pm

    • You can easily modify the above script to do that.

      Comment by yasi8h — August 18, 2010 @ 1:39 am

  2. Hi
    I get the following when I try to run the script from my desktop:

    input folder: /1 outp folder: /2

    b@z60m:~/Skrivebord$ bash> ruby photo_org.rb /1 /2 dirs
    photo_org.rb: line 3: require: command not found
    photo_org.rb: line 4: require: command not found
    photo_org.rb: line 5: require: command not found
    photo_org.rb: line 7: require: command not found
    photo_org.rb: line 8: require: command not found
    photo_org.rb: line 9: require: command not found
    photo_org.rb: line 11: class: command not found
    photo_org.rb: line 13: def: command not found
    photo_org.rb: line 14: log: command not found
    photo_org.rb: line 16: syntax error near unexpected token `argv[0],’
    photo_org.rb: line 16: `[0], log).walk_the_source_dir do |path|’

    I have instelled rubygems 1.9.1 and run gem install exif.

    Would love to have this script working…

    Comment by Bjørnar — September 25, 2010 @ 7:08 pm

  3. @Bjørnar

    Take a look at this post:

    “What had happened was I hadn’t deleted the tab spaces before the #!/usr/bin/env ruby line.

    Apparently if there is any white space before the #!/usr/bin/env ruby the script will not run.”

    Comment by yasi8h — September 26, 2010 @ 12:40 am

  4. Nice script but I noticed that the log doesn’t work. I get this after processing a few thousand images. Is there anything I’m doing wrong?

    Time = Wed Dec 08 16:56:47 -0800 2010
    Source Directory = files/
    Dest Directory = organizedpictures/
    Files with valid EXIF data = 0
    Files with invalid EXIF data = 0
    Files with invalid_ext = 0
    Duplicate files = 0
    Files with same timestamp = 1
    Unique files = 1

    Comment by Ryan — December 9, 2010 @ 1:03 am

    • @ryan Hmm, do you get any errors while running the script? And is your files actually being processed?

      Comment by yasi8h — December 9, 2010 @ 1:29 am

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at

%d bloggers like this: