以前フォルダーがぶっ飛んでしまいサルベージされたもののファイル名が「FILExxxxx」になったり、タイムスタンプがサルベージした時間に変わってしまったものを perl スクリプトを書いて復旧させてみました。Image::ExifTool 以外は標準モジュールです。
復旧させたファイルを適当に flickr へ載せてみました。
#! /usr/local/bin/perl -w
eval 'exec /usr/local/bin/perl -S $0 ${1+"$@"}'
if 0; #$running_under_some_shell
use strict;
use File::Find qw();
use Time::Local;
use POSIX;
use Image::ExifTool 'ImageInfo';
sub Rename ($){
my $info = ImageInfo($_);
if (defined($$info{'DateTimeOriginal'})){
undef $$info{'ThumbnailImage'};
# 'DateTimeOriginal' => '2006:01:03 18:39:02'
$$info{'DateTimeOriginal'} =~ /^(\d{4}):(\d{2}):(\d{2}).(\d{2}):(\d{2}):(\d{2})$/;
my $ShotTime = timelocal($6, $5, $4, $3 , $2 - 1, $1 - 1900);
print "DateTimeOrignal: $$info{'DateTimeOriginal'}\n",
strftime("timestamp to: %F %T\n", $6, $5, $4, $3 , $2 - 1, $1 - 1900);
#--- utime $ShotTime, $ShotTime, $_;
# 'FileNumber' => '121-2187',
$$info{'FileNumber'} =~ /^\d{3}-(\d{4})$/;
print "$_ chenge to IMG_${1}.JPG\n";
#--- rename $_, "IMG_${1}.JPG";
}else{
print "$_: Can not found DateTimeOriginal. This file Skip!";
}
}
# Set the variable $File::Find::dont_use_nlink if you're using AFS,
# since AFS cheats.
# for the convenience of &wanted calls, including -eval statements:
use vars qw/*name *dir *prune/;
*name = *File::Find::name;
*dir = *File::Find::dir;
*prune = *File::Find::prune;
sub wanted;
# Traverse desired filesystems
File::Find::find({wanted => \&wanted}, '.');
exit;
sub wanted {
# if(/^FILE.*\z/s) {
if(/^IMG_.*\z/s) {
printf("___ $name ___\n");
Rename ($name);
}
}
こんな感じ。eval 'exec /usr/local/bin/perl -S $0 ${1+"$@"}'
if 0; #$running_under_some_shell
use strict;
use File::Find qw();
use Time::Local;
use POSIX;
use Image::ExifTool 'ImageInfo';
sub Rename ($){
my $info = ImageInfo($_);
if (defined($$info{'DateTimeOriginal'})){
undef $$info{'ThumbnailImage'};
# 'DateTimeOriginal' => '2006:01:03 18:39:02'
$$info{'DateTimeOriginal'} =~ /^(\d{4}):(\d{2}):(\d{2}).(\d{2}):(\d{2}):(\d{2})$/;
my $ShotTime = timelocal($6, $5, $4, $3 , $2 - 1, $1 - 1900);
print "DateTimeOrignal: $$info{'DateTimeOriginal'}\n",
strftime("timestamp to: %F %T\n", $6, $5, $4, $3 , $2 - 1, $1 - 1900);
#--- utime $ShotTime, $ShotTime, $_;
# 'FileNumber' => '121-2187',
$$info{'FileNumber'} =~ /^\d{3}-(\d{4})$/;
print "$_ chenge to IMG_${1}.JPG\n";
#--- rename $_, "IMG_${1}.JPG";
}else{
print "$_: Can not found DateTimeOriginal. This file Skip!";
}
}
# Set the variable $File::Find::dont_use_nlink if you're using AFS,
# since AFS cheats.
# for the convenience of &wanted calls, including -eval statements:
use vars qw/*name *dir *prune/;
*name = *File::Find::name;
*dir = *File::Find::dir;
*prune = *File::Find::prune;
sub wanted;
# Traverse desired filesystems
File::Find::find({wanted => \&wanted}, '.');
exit;
sub wanted {
# if(/^FILE.*\z/s) {
if(/^IMG_.*\z/s) {
printf("___ $name ___\n");
Rename ($name);
}
}
復旧させたファイルを適当に flickr へ載せてみました。