Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the '10.4: Set a photo file's creation date to the photo's date' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.4: Set a photo file's creation date to the photo's date
Authored by: merlyn on Jan 05, '07 11:28:42AM
I've been using this Perl script for a long time now:

#!/usr/bin/env perl
use strict;
$|++;

use Image::ExifTool qw(ImageInfo);

use Time::Local;

for my $file (@ARGV) {
  my $ii = ImageInfo($file, qw(DateTimeOriginal DateTime))
    or warn("Skipping $file\n"), next;
  my ($created) =
    grep /\S/, @$ii{qw(DateTimeOriginal DateTime)};
  next unless $created;
  warn "using $created for $file\n";
  if ($created =~ s/([-+ ])(\d\d):(\d\d)$//) {
    my ($sign, $hour, $minute) = ($1, $2, $3);
    # warn "ignoring offset of $sign $hour:$minute\n";
  }
  my @digits = $created =~ /(\d+)/g or next;
  if ($digits[0] < 1900) {
    warn "bad year $digits[0] for $file";
    next;
  }
  $digits[0] -= 1900;
  $digits[1] -= 1;
  my $gmtime = timegm(reverse @digits);
  if ($gmtime > time or $gmtime < time - 86400*90) {
    warn "preposterous gmtime for $file: ", scalar gmtime $gmtime;
    # next;
  }
  utime($gmtime, $gmtime, $file) or warn "Cannot utime on $file: $!";
}
It requires Image::ExifTool installed from the CPAN.

[ Reply to This | # ]
10.4: Set a photo (ANY) file's creation date to the photo's date
Authored by: peterrosen on Mar 21, '08 05:15:10PM

I don't know how it happened, but all of a sudden a bunch of files are now showing modified date of today, rather than the last time they were created or touched. Is there a way to reset the change? I have no idea how these files all either images (png and jpg) and .mov files were changed or what did it? I would sure love a way to be able to see where and when my energy went into the particular image/mov as that's part of how i keep track of my progress and time spent on things. TIA for an APPLESCRIPT ideally, or whatever.

peter



[ Reply to This | # ]