Author Topic: Copy metadata to corresponding files  (Read 1026 times)

grole

  • Jr. Member
  • **
  • Posts: 26
Copy metadata to corresponding files
« on: December 24, 2016, 10:05:09 AM »
I've always kept two sets of my photos: the originals and an edited set, in separate folders. I've added IPTC data to the edited set only (keywords and captions).

Now I'd like to copy this data from the edited set to the corresponding photos in the originals folder, in order to r-edit them. Is there a way to do this as a batch?

Note: the filenames are identical, but not all originals were edited, so the edited set has somewhat less than the originals. There are no files in the edited set which are not also in the originals, however.

Thanks in advance!

Hayo Baan

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 775
  • Professional Photographer and Workshop Leader
    • Hayo Baan – Photography
Re: Copy metadata to corresponding files
« Reply #1 on: December 24, 2016, 11:10:53 AM »
This shouldn't be too hard to accomplish. A simple:
Code: [Select]
exiftool -tagsfromfile EDITDDIR/%f.%e ORGDIRWill copy all metadata from the files in EDITDIR to corresponding files in ORGDIR, keeping the original file as _original. If no corresponding file is found in EDITDIR, a warning will be issued and the original will not be updated (which is great in this case).I don't recommend updating all metadata though, just the things you are interested in. This can be done too, just specify the tags you want copied after the -tagsfromfile option. E.g. to copy only the IPTC metadata, use:
Code: [Select]
exiftool -tagsfromfile EDITDIR/%f.%e -iptc:all ORGDIR
If you have organised your files in subdirectories, change your current directory to the root dir of the original images and run the following (. denotes the current directory):
Code: [Select]
exiftool -r -tagsfromfile EDITDIRROOT/%d/%f.%e -iptc:all .
Finally, this more fancy version of the command will create copies of the the original using the IPTC from the edited files for all edited files into a new location. You need to start this from the EDITDIRROOT.

Code: [Select]
exiftool -r -tagsfromfile ./%d/%f.%e -srcfile ORGDIRROOT/%d/%f.%e -o NEWROOT/%d/%f.%e -iptc:all .
Hope this works for you :)
Hayo Baan – Photography
Web: www.hayobaan.nl
Blog: blog.hayobaan.nl
500px: 500px.com/HayoBaan

grole

  • Jr. Member
  • **
  • Posts: 26
Re: Copy metadata to corresponding files
« Reply #2 on: December 26, 2016, 08:51:59 PM »
Hi, thanks a lot for the answer. I didn't get to try it until now due to another problem: https://www.dpreview.com/forums/thread/4095667#forum-post-58859991. (well, and also Christmas!)

It didn't quite work. I copied some test files directly into my E: drive, under "original" and "edited" respectively. So both folders are directly under root - as I'm not sure how to write the syntax for the 2nd folder level. Is it "e:folder\subfolder? Or e:folder/subfolder?

Anyway, here's what I entered and what I got:

C:\>exiftool -tagsfromfile e:edited/%f.%e -iptc:all e:original
Warning: Error opening file - e:edited/e:original.
Error: File not found - e:original
    0 image files updated
    1 files weren't updated due to errors


What did I do wrong?

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 11572
    • ExifTool Home Page
Re: Copy metadata to corresponding files
« Reply #3 on: December 26, 2016, 09:21:27 PM »
Either forward or backslashes is fine, but try putting a slash after "e:" (both in the input file and the -tagsFromFile argument.

- Phil
...where DIR is the name of a directory containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

grole

  • Jr. Member
  • **
  • Posts: 26
Re: Copy metadata to corresponding files
« Reply #4 on: December 28, 2016, 04:42:18 PM »
Hi Phil, thanks for that. It worked. I used:

exiftool -tagsfromfile e:\test\main/%f.%e -iptc:all e:\test\negatives -overwrite_original

Note that I'm using "negatives" as the original folder and "main" as the edited folder.

If I can, I'd like to refine this. And perhaps you could help with the syntax:
  • Change the -iptc:all to a string which only overwrites the caption-abstract and keywords fields, thus not overwriting any other info by mistake
  • Be able to do this on files in subdirectories (1 level). For examble my file structure is:

    Negatives
      2016
        01 Jan 01
        01 Jan 02
        01 Jan 04
        etc.

    Main
      2016
        01 Jan 01 Visiting Friends
        01 Jan 02 Driving Home
        01 Jan 04 Kids Playing
        etc.

    So it would be good to be able to perform this on, for example, all files found in all subdirectories of 2016 in the "main" and "negatives" folders respectively. Note that I've added a description in the folder names of the main set only, although the stem (date) is always the same. Also, any files found in a single day's folder of the main set will be found in the corresponding folder of that date in the negative set, and nowhere else. The file names themselves are always unique (sequentially named).
  • On a side note: what syntax do I have to use for folder names with blanks in them? Until now I've had to use folder names without blanks, as it gives an error.
  • On another side note: could I do the same to overwrite the exif "date/time original", or simply all date/time fields? What would be the syntax for that?

Thanks in advance!

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 1225
Re: Copy metadata to corresponding files
« Reply #5 on: December 28, 2016, 04:56:59 PM »
Change the -iptc:all to a string which only overwrites the caption-abstract and keywords fields, thus not overwriting any other info by mistake

Change -iptc:all to -Caption-Abstract -Keywords

Quote
Be able to do this on files in subdirectories (1 level). For examble my file structure is:

Hmmm… I don't see any easy way to do that, hopefully someone else can come up with something.

Quote
On a side note: what syntax do I have to use for folder names with blanks in them? Until now I've had to use folder names without blanks, as it gives an error.

Assuming Windows by your examples, put double quotes around the path.  For example "e:\test\negatives\2016\01 Jan 01"

Quote
On another side note: could I do the same to overwrite the exif "date/time original", or simply all date/time fields? What would be the syntax for that?

For just DateTimeOriginal, use -DateTimeOriginal.  For the most common useful tags, use the -AllDates shortcut, which includes the EXIF tags: DateTimeOriginal, CreateDate, and ModifyDate.  To do all Date/Time tags, you could use -Time:All.
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If you GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.

grole

  • Jr. Member
  • **
  • Posts: 26
Re: Copy metadata to corresponding files
« Reply #6 on: December 28, 2016, 05:08:00 PM »
Perfect! Thanks a lot.

If anyone has an idea about the subdirectories, that'd be great. Otherwise I'll just have to dump them into one folder for the operation, then use Downloader Pro to re-file them.

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 1225
Re: Copy metadata to corresponding files
« Reply #7 on: December 28, 2016, 05:30:09 PM »
Otherwise I'll just have to dump them into one folder for the operation, then use Downloader Pro to re-file them.

Personally, I'd suggest saving the path to a tag you don't use before you dump, then you could move them back afterwards.   Since you were originally looking at IPTC tags, maybe use XMP:Title or XMP:Description. (strike this, based upon your other post mentioned ACDSee, this wouldn't be a good option). Or maybe pick a rarely used tag like one of the Creative Commons tags.

For example, you could use:
exiftool "-AttributionName<Directory" -r e:\test\negatives

And that will save the directory into the the files.  The -r in that command recurses into all the subdirectories.

You could then move them to the single directory to process. 
exiftool -Directory=e:\ProcessingDirectory -r e:\test\negatives

Then you could put them back in the proper places with:
exiftool "-Directory<AttributionName" e:\ProcessingDirectory

And then finally, if you like, clear out the now unnecessary tag with:
exiftool -AttributionName= -r e:\test\negatives

Edit: Crossed out suggestion based upon program mentioned in other post.

PH Edit: Added links to other post
« Last Edit: December 29, 2016, 08:19:43 AM by Phil Harvey »
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If you GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.

grole

  • Jr. Member
  • **
  • Posts: 26
Re: Copy metadata to corresponding files
« Reply #8 on: December 29, 2016, 12:52:29 AM »
That sounds like a better option, especially since Downloader Pro could not re-file them into the folders which have descriptions added.

I might not get to this for a while but when I do, I'll report back.

Quote
based upon your other post mentioned ACDSee, this wouldn't be a good option

Just curious, do you mean I shouldn't use the xmp fields because if I'm using ACDSee those fields wouldn't be empty? I asked about general captioning strategy in the other post... I normally use Lightroom, although it allso appears to write to xmp. Perhaps there is a better tool for entering/maintaining captions?

Thanks!

PH Edit: Added link to other post
« Last Edit: December 29, 2016, 08:19:19 AM by Phil Harvey »

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 1225
Re: Copy metadata to corresponding files
« Reply #9 on: December 29, 2016, 01:15:35 PM »
Just curious, do you mean I shouldn't use the xmp fields because if I'm using ACDSee those fields wouldn't be empty?

Yes.  You were posting about IPTC so I assumed you weren't using XMP.  But since you're using LR and ACDSee and those write to XMP, writing to the first tags I suggested would cause problems.  While writing my post, I went looking for other possibilities and realized I had never seen a Creative Common tag used, so I suggested that and probably will suggest it in the future as a 'scratch' tag.

Quote
I normally use Lightroom, although it allso appears to write to xmp. Perhaps there is a better tool for entering/maintaining captions?

Lightroom and ACDSee are probably better than most programs.  I have yet to find a program that didn't have some oddities about the way it writes metadata, though I haven't tried ACDSee (don't have the budget for it).  Even Lightroom 4.4 (the only version I have access too) doesn't write the same values to XMP:Description and IPTC:Caption-Abstract, as it will write New Lines to one and Carriage Returns to the other.  I have no idea about later versions.
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If you GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.

grole

  • Jr. Member
  • **
  • Posts: 26
Re: Copy metadata to corresponding files
« Reply #10 on: January 11, 2017, 05:31:24 PM »
Hi again,

I just tried this process out on a large test batch and it worked perfectly! Aside from some earlier files, where I'd actually renamed one set (duhh), it looks like this is going to be just what I need.

Thanks again for all the help!

grole

  • Jr. Member
  • **
  • Posts: 26
Re: Copy metadata to corresponding files
« Reply #11 on: January 15, 2017, 04:01:29 PM »
Hi again,

Just a quick question, somewhat releated. How would I write a command to write either the same value to multiple fields (in this case to clear them). I'm looking to avoid running two or more batches.

Based on this:

exiftool -AttributionName= -r e:\test\negatives

Say I'd want to also clear -Title with the same command?

Thanks!

Hayo Baan

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 775
  • Professional Photographer and Workshop Leader
    • Hayo Baan – Photography
Re: Copy metadata to corresponding files
« Reply #12 on: January 15, 2017, 04:51:04 PM »
You can set multiple tags in a single run. So in this case, simply add -Title= to your exiftool command.
Hayo Baan – Photography
Web: www.hayobaan.nl
Blog: blog.hayobaan.nl
500px: 500px.com/HayoBaan