Created
December 23, 2010 16:27
-
-
Save yukioc/753210 to your computer and use it in GitHub Desktop.
JPEG file renamer(use exiftime)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fixed a problem that one day late the modified file name (2011-01-30)