Hi Bette,
The exiftool application can't do this from a single txt file. It can
do this sort of thing from multiple XML files (-X option) if this
will suit your needs, but you need one XML file for each image file.
But to do exactly what you want is quite simple with
a bit of Perl script and the Image::ExifTool library:
#!/usr/bin/perl -w
#
# File: write_from_txt
#
# Description: Read text file and write tags to image file
#
# Syntax: write_from_txt TXTFILE [TAGS]
#
# Notes: 1) TAGS must not have leading dashes
#
# 2) TXTFILE must be written with a command like:
#
# exiftool -s DIR > out.txt
#
use strict;
use Image::ExifTool;
my $infile = shift or die "SYNTAX: write_from_txt INFILE [TAGS]\n";
open INFILE, $infile or die "Error opening '$infile'\n";
my $exifTool = new Image::ExifTool;
# split lists into individual items when writing
$exifTool->Options(ListSplit => ', ');
# uncomment this line for additional debugging output
#$exifTool->Options(Verbose => 2);
my ($imageFile, $tag, $val);
# loop through each line in the TXT file
for (;;) {
my $line = <INFILE>;
if (defined $line) {
if ($line =~ /^======== (.*)\n$/) {
# get full file path name
($tag, $val) = ('PathName', $1);
} else {
# read tag name and value from TXT file
next unless $line =~ /^(\S+)\s*:\s+(.*)\n$/;
($tag, $val) = ($1, $2);
}
} else {
$tag = 'PathName';
undef $val;
}
if ($tag eq 'PathName') {
if ($imageFile) {
# write the previous file
my $result = $exifTool->WriteInfo($imageFile);
my $error = $exifTool->GetValue('Error');
if ($error) {
warn "$error - $imageFile\n";
} elsif ($result == 2) {
warn "Nothing changed - $imageFile\n";
} else {
print "Updated $imageFile OK\n";
}
}
last unless defined $val;
$imageFile = $val;
$exifTool->SetNewValue(); # clear previous values
print $line;
next;
}
# set tag if specified (or if no tags specified)
next if @ARGV and not grep /^$tag$/i, @ARGV;
print " Writing $tag\n";
$exifTool->SetNewValue($tag, $val);
}
# end
Note that exiftool will attempt to write the value of any tag stored
in the text file (unless you specify individual tags on the command
line for this script). This includes the FileName tag, but writing of this
tag will fail because it is protected.
- Phil