Image-ExifTool - Re: update-write iptc or xmp based on csv file

Posted on Fri Jul 20 16:23:38 2007 by exiftool in response to 5774 (See the whole thread of 5)
Re: update-write iptc or xmp based on csv file
Things like this can't be done with the current command-line interface. Instead things like this are done by writing custom scripts which use the ExifTool library to do most of the work.

I don't know the exact format of your file, but assuming that the columns are separated by tabs, and that the first row contains the filename and the actual tag names that you want to change, here is a script that will do what you want:

#!/usr/bin/perl -w use strict; BEGIN { # add script directory to include path my $exeDir = ($0 =~ /(.*)[\\\/]/) ? $1 : '.'; unshift @INC, "$exeDir/lib"; } use Image::ExifTool; my $txt = shift or die "Syntax: SCRIPT TEXTFILE [DIR]\n"; open FILE, $txt or die "Error opening $txt\n"; my $dir = shift || ''; $dir .= '/' if $dir; my $exifTool = new Image::ExifTool; my @tags; while (<FILE>) { chomp; # split up values found in this line (assume tab delimiter) my @values = split /\t/, $_; next unless @values; unless (@tags) { $values[0] eq 'filename' or die "Expected 'filename' not found\n"; shift @values; @values or die "No tags found\n"; @tags = @values; print "Writing tags: @tags\n"; next; } my $file = $dir . shift(@values); unless (-e $file) { warn "$file not found\n"; next; } @values >= @tags or die "Not enough values for $file\n"; my $tag; $exifTool->SetNewValue(); # clear old values # set new values for all tags foreach $tag (@tags) { my $val = shift @values; $exifTool->SetNewValue($tag, $val); } # update the file my $result = $exifTool->WriteInfo($file); if ($result == 1) { print "$file updated\n"; } elsif ($result == 2) { print "$file not changed\n"; } else { print "$file - write error!\n"; last; } } # end

- Phil
Direct Responses: 5778 | 7778 | Write a response