ExifTool Forum

ExifTool => The Image::ExifTool API => Topic started by: sjDelaney on May 07, 2016, 05:58:31 PM

Title: Checking if xml exists and using another -srcfile if none exists.
Post by: sjDelaney on May 07, 2016, 05:58:31 PM
Quote from: Phil Harvey on June 17, 2012, 08:58:14 PM
I am thinking about implementing this without adding any new options.  I think I can do what you want by allowing multiple -srcfile options to specify more than one source.  If the first specified source file doesn't exist, then exiftool would move on to the next, etc.  If none exists, exiftool would attempt to write the first one in list anyway (ie. to create a .XMP file).  The command would be something like this:

exiftool -srcfile %d%f.xmp -srcfile @ -artist=me -ext nef DIR

This command would write to a sidecar XMP if it exists, otherwise to the original raw file for all NEF images in directory DIR.

Provided there are not hitches in implementation, this could appear in ExifTool 8.96

- Phil



This comes from an old thread, but it concludes with confirming that multiple -srcfile (s) can be used for read and write.

...-srcfile finename.xmp -srcfile filename.nef...

The example you give is for command line; what would that look like using the API?
Title: Re: Checking if xml exists and using another -srcfile if none exists.
Post by: sjDelaney on May 08, 2016, 10:17:42 AM
Never mind.  I thought it through.  Dumb question.
Title: Re: Checking if xml exists and using another -srcfile if none exists.
Post by: sjDelaney on May 12, 2016, 12:02:17 PM
Actually I thought I had this resolved but I'm not quite there.  I'm sure I have the Perl logic current (it tests out), but the output (xmp) files are huge and seem to be actually jpegs with xml extensions.  They are huge (Up to 14MB), Preview in Finder as images, and are unreadable with a text editor.

Here is the WriteInfo syntax I'm using...

$Write = $exifTool->WriteInfo($File,$XMPFile);    #Where $File is a jpg but could potentially be a raw file.

I tried to update a relatively small output file (2MB) as an attachment, but the post would not accept it.
Title: Re: Checking if xml exists and using another -srcfile if none exists.
Post by: Phil Harvey on May 12, 2016, 01:18:57 PM
Right.  WriteInfo() only writes metadata to the specified file.  It does not change file types.  The exiftool application calls SetNewValuesFromFile() then WriteInfo() with an undef source file to create an XMP file from scratch.

- Phil