Renaming files while updating metadata

Started by Archive, May 12, 2010, 08:54:07 AM

Previous topic - Next topic

Archive

[Originally posted by toosubtle on 2007-08-11 06:35:48-07]

I want to rename files while optionally updating other metadata (copyright, etc).  I find that when I change only the FileName tag, then the files get renamed.  If I change any other metadata in addition to FileName, then the files don't get renamed, but *copied* to the new filename (old still exists).  Seems inconsistent.  What am I doing wrong?

Here's an outline of my code:

Code:
sub renameandstamp
{
   my ($oldname, $newname, $stampmeta) = @_;
   my $exifTool = new Image::ExifTool;
   
   # if told to do so, stamp other metadata
   if ($stampmeta)
   {
      my $info = $exifTool->ImageInfo($oldname, keys(%metadatatemplate));
                ...
           my ($success, $errStr) = $exifTool->SetNewValue($tag, $newvalue);
   }
   
   # set the new name
   my ($success, $errStr) = $exifTool->SetNewValue("FileName", $newname, Protected => 0x01);

   # commit the change
   my $result = $exifTool->WriteInfo($oldname);
}

I had assumed that since I'm only specifying the source file to WriteInfo, that it would always do a rename (no copies).  At least that's how I understood the doc: http://www.exiftool.org/ExifTool.html#WriteInfo.  

I could add a hack to delete the source after WriteInfo if $stampmeta is true and WriteInfo was a success, but I'd rather figure out how to get WritInfo to do the same thing each time.

Thanks!

Archive

[Originally posted by toosubtle on 2007-08-13 20:40:42-07]

Forgot to mention: this is ExifTool ver 6.90.

Archive

[Originally posted by exiftool on 2007-08-16 11:27:16-07]

True, this is a bit inconsistent.  However, this is the way it is designed.
The pseudo tags Filename, Directory and FileModifyDate are treated
slightly differently since the file is not rewritten if only these tags are
modified.  But when a file is rewritten, it is up to the calling program
to delete the original if required.  The ExifTool library functions won't
delete the original unless you are rewriting in place, which can't be
done when you are changing the file name.

- Phil

Archive

[Originally posted by toosubtle on 2007-08-20 23:24:35-07]

Thanks Phil!  Could you update the docs to reflect this?  Just a quick sentence or two will save others time & scratching their heads.

Archive

[Originally posted by exiftool on 2007-08-21 00:08:37-07]

This note already exists in the
Extra Tags
documentation:

The three writable "pseudo" tags (Filename, Directory and FileModifyDate)
may be written without the need to rewrite the file since their values are not
contained within the file data.


Of course, the trick is to find it.  I am open to suggestions if you have a better
wording, or could suggest a better place to document this.

- Phil

Archive

[Originally posted by exiftool on 2007-08-21 00:14:19-07]

Ah. I re-read your initial post and see you were referring to the
WriteInfo() function documentation.  I will add a note to this
documentation to try to clear up this behaviour.

- Phil

Archive

[Originally posted by toosubtle on 2007-08-21 00:46:49-07]

Aha!  I hadn't thought to look there - I was looking in the WriteInfo docs since that's what I was calling.  The description for the destination param just says "The destination file name may be undefined to edit a file in place (make sure you have backups!)."  That'd be a great place to put a caveat or cross ref.  

Thanks!

Archive

[Originally posted by exiftool on 2007-08-21 20:38:54-07]

In the end I decided it was better to change this behaviour to make it
this behaviour more consistent instead of trying to document it.  Version
6.95 (just released) now deletes the original file in this case.  I believe
this was the only case where a second file could remain after calling
WriteInfo() with one argument, so it made more sense to just go ahead
and delete it.

- Phil