Skip to content

Instantly share code, notes, and snippets.

@yukioc
Created December 23, 2010 16:27
Show Gist options
  • Save yukioc/753210 to your computer and use it in GitHub Desktop.
Save yukioc/753210 to your computer and use it in GitHub Desktop.
JPEG file renamer(use exiftime)
#!/usr/bin/env perl
use strict;
use warnings;
my $exe= '/usr/bin/exiftime';
#my $exe= '/usr/bin/exiftags -v';
foreach my $file (@ARGV){
if (-e $file && $file =~ /\.(jpg|JPG)$/){
my ($exif)=grep(/Image (Created|Generated|Digitized):/,`$exe $file`);
if ($exif && $exif=~s/^Image .*?: (.*)//){;
my ($y,$m,$d,$h,$M,$s)=split(/[: ]/,$1);
my $new=sprintf "%04d%02d%02d_%02d%02d%02d",$y,$m,$d,$h,$M,$s;
my ($ext) = map{ /.*\.(.*)/ } ($file);
$new .= ".$ext" if($ext);
if ($file ne $new && !-e $new){
printf "$file -> $new\n";
rename $file,$new;
}
}
}
}
@yukioc
Copy link
Author

yukioc commented Jan 30, 2011

Fixed a problem that one day late the modified file name (2011-01-30)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment