User Tools

Site Tools


howtos:move_pictures_by_date

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

howtos:move_pictures_by_date [d/m/Y H:i] (current)
Line 1: Line 1:
 +====== Reorganize script ======
 +This script takes one parameter, the directory to where your pictures (or files) resides. It then creates a directory with the name of the creation date and move the picture/file into it.
 +The directory name is in this format: YYYY-MM-DD
  
 +<file>
 +#!/bin/bash
 +
 +for i in $(ls $1); do
 + CREATEDATE=$1/`date -r $1/$i +%F`
 + SRC=$1/$i
 + if [ -d $CREATEDATE ]; then
 + mv $SRC $CREATEDATE
 + else
 + mkdir $CREATEDATE
 + mv $SRC $CREATEDATE
 + fi
 +done
 +</file>
 +
 +This can be used to organize pictures into a folder structure easily used by a gallery (that's at least what I'm using it for).
 +
 +Hope you like it.
 +
 +**Update:**
 +If you want to use underscore as separators in the directory names use this edition instead:
 + 
 +<file>
 +#!/bin/bash
 +
 +for i in $(ls $1); do
 + CREATEDATE=$1/`date -r $1/$i +%Y_%m_%d`
 + SRC=$1/$i
 + if [ -d $CREATEDATE ]; then
 + mv $SRC $CREATEDATE
 + else
 + mkdir $CREATEDATE
 + mv $SRC $CREATEDATE
 + fi
 +done
 +</file>
 +
 +By changing the date command (see man pages) you can make a naming layout that suite you best. Just change the parameters after the "+" sign.
 +
 +
 +**Update #2:**
 +
 +If you have a bunch of jpg files and you've lost their creation date you can extract it from an exif tag (if it is set by the camera, wich they usually are). This script will do just that. Note however that it is ONLY jpg files:
 +
 +Remember to install exiftool (sudo apt-get install libimage-exiftool-perl)
 +
 +<file>
 +#!/bin/bash
 +
 +for i in $(ls $1); do
 + CREATEDATE=$1/`exiftool -d %Y_%m_%d -CreateDate $1/$i |cut -d: -f2|  sed -e 's/^[ \t]*//'`
 + SRC=$1/$i
 + if [ -d $CREATEDATE ]; then
 + mv $SRC $CREATEDATE
 + else
 + mkdir $CREATEDATE
 + mv $SRC $CREATEDATE
 + fi
 +done
 +</file>
howtos/move_pictures_by_date.txt · Last modified: d/m/Y H:i (external edit)