Scotech Scotech
Knowledge Base
[ Home | KB | Tools | Requests? ]


Rename Digital Photos by Date Taken


This script will rename a batch of digital photos in JPEG format based on the date they were taken. It requires the EXIF data on the camera to be correct.

#!/usr/bin/perl

use strict;
use Image::EXIF;

my @list = `ls -1 *JPG *jpg *JPEG *jpeg`;
my $exif = new Image::EXIF;
for my $fname (@list) {

  chomp $fname;

  $exif->file_name($fname);
  my $data = $exif->get_all_info();

  if ($data) {

    my $timestamp = $data->{image}->{'Image Created'};
    (my $date, my $time) = split(/ /, $timestamp);
    $date =~ s/\://g;

    my $count = '001';
    while (-f "$date $count.jpg") { $count++; }

    rename $fname, "$date $count.jpg";

  }

}

Obviously you can adjust the script to rename the files any way you wish. You will need a couple of perl modules in order to execue the script.

- Scotech



[ Home | KB | Tools | Email: info@scotech.com ]

© 1996-2010 Scotech. All rights reserved.