sync keywords between mirrored tree folders structure

Started by SergeS, July 06, 2018, 02:55:00 PM

Previous topic - Next topic

SergeS

Have never use exiftool before, but i think it is exactly what i need :-).

I have two "mirrored" branches of folders, one with raw-files, the other one with jpeg-files, produced from these raw-files.
I have some mess with keywords, related jpegs and raws sometimes were tagged asynchronously and now they not perfectly matching to each other.
I would like to restore synchronization.
Can someone give me help, how I can make a windows batch file, recursively scanning one branch of folders, with raw-files, read all keywords and write them into respective file in respective location in another, jpeg, branch of folders. I believe it is a typical task, someone did it before... Are there any useful gui tools for such things?

StarGeek

There's no need for a batch file, a single command can do this.

First, you CD into the top directory of the jpeg files.  Then you can run this (assuming NEF raws, change to appropriate extention):
exiftool -ext Jpg -r -TagsFromFile C:\Path\To\RawFiles\%d%f.NEF -Keywords .

This will search the current directory, indicated by the dot ., recurse into subdirectories (the -r option), only looking at jpgs (the -ext option) and then look for a matching raw file (NEF in this case).  It looks in C:\Path\To\RawFiles\ followed by the relative directory of the jpg (the %d), the filename of the jpeg (the %f), followed by the raw extension (.NEF).  This becomes the Source file for the -TagsFromFile optionKeywords are then copied from that file to the target jpeg.

If you need to use full directory paths (e.g. C:\Path\To\JpgFiles\) instead, it becomes much more complicated.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

SergeS

Seems like that is what i need, thank you, will try on weekend.

One more thing i've forgot to mention - i would like to preserve timestamp of files where tags are written to. Is this possible?

StarGeek

* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

SergeS

Thank you, seems like it is exactly what i need.

Last (i believe) question - when it is copying keywords to the file with already existing existing, new keywords will be added to existing ones or will overwrite existing ones?

StarGeek

#5
Overwritten. See note #5 under -TagsFromFile option and use -AddTagsFromFile instead.

edit: oops, nevermind
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Phil Harvey

Quote from: SergeS on July 08, 2018, 01:36:28 PM
Last (i believe) question - when it is copying keywords to the file with already existing existing, new keywords will be added to existing ones or will overwrite existing ones?

Overwritten as StarGeeks says.

But (and this can be a bit confusing) the -addTagsFromFile option is used to add to new keywords when copying from other tags.  So your existing keywords are still overwritten with -addTagsFromFile.

To add to existing keywords, use "-keywords+<keywords" when copying.

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

SergeS

Have found some time to play with it, I like it :-). Thank you everybody for advises and good software.

I was able to sync all keywords from NEFs to jpgs using command:
exiftool -ext Jpg -r -P -progress -overwrite_original -TagsFromFile "my_RAW_folder\%d%f.NEF" -Keywords .
running from jpg-folder as current.

But i was not able to sync in opposite direction, command:
exiftool -ext NEF -r -P -progress -overwrite_original -TagsFromFile "my_jpg_folder\%d%f.jpg" -Keywords .
running from RAW-folder as current did not update any keywords, although did not give me any error.

Are there any ideas why?

Hayo Baan

Did exiftool say xx files unchanged perhaps? If you first ran the command to copy from jpg to raw, then doing it the other way around would not have made any changes since both sets would already have the same keywords.
Hayo Baan – Photography
Web: www.hayobaan.nl

SergeS

Here is more details what i have done.
Before run ExifTool I have prepared my files, all jpgs got "TEST-JPG" tag, all raws got "TEST-RAW".

After first run of Exiftool (to copy keywords from raws to jpgs) all jpgs have both tags, raws were not changed. That is what i have expected.
And yes, keywords are not overwritten, they have been added to existing keywords.

After second run (to copy keywords from jpgs to raws) raws still have only one tag "TEST-RAW", this is not what i expected.
Actually. I did not see any changes of raw failes.

ExifTool reported all 99 files were updated, even if i run the same command twice in a row :-).

<.........>
======== ./DSC_1279.NEF [96/99]
======== ./DSC_1162.NEF [97/99]
======== ./DSC_1164.NEF [98/99]
======== ./DSC_1163.NEF [99/99]
    1 directories scanned
   99 image files updated

\\NAS\photo\...W)\2017\2017_09_02, Manhattan, Central park>

Phil Harvey

To add to existing keywords, you need "-keywords+<keywords" instead of just -keywords in your command.

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

SergeS

Quote from: Phil Harvey on July 22, 2018, 04:14:37 PM
To add to existing keywords, you need "-keywords+<keywords" instead of just -keywords in your command.

I am observing addition with -keywords, when copying keywords from raws to jpgs. Where is my mistake?

p.s. Using "-keywords+<keywords" instead of -keywords gave me extra warnings, see below. Keywords are still with no changes.

======== ./DSC_1162.NEF [98/99]
Warning: Shift value for XMP-xmp:Keywords is not a number - \\NAS\photo\Serge\Test\Family Archive\2017\2017_09_02, Manhattan, Central park\./DSC_1164.jpg
======== ./DSC_1163.NEF [99/99]
Warning: Shift value for XMP-xmp:Keywords is not a number - \\NAS\photo\Serge\Test\Family Archive\2017\2017_09_02, Manhattan, Central park\./DSC_1163.jpg
    1 directories scanned
   99 image files updated

\\NAS\photo\...W)\2017\2017_09_02, Manhattan, Central park>


Phil Harvey

Quote from: SergeS on July 22, 2018, 04:43:43 PM
I am observing addition with -keywords, when copying keywords from raws to jpgs. Where is my mistake?

Try it on one file and look at exiftool -keywords -a -G1 FILE before and after, and show me your commands and the output and I should be able to figure it out.

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

SergeS

I think I see the problem - commands above  copy keywords only from/to IPTC area, correct?
But my software (Daminion) I have used to set initial keywords and to verify results of those commands is setting and reading keywords from/to few different locations, see screenshot of ExifToolGUI below.
So, when I have copied keywords first time, from raw to jpg - only IPTC has been updated (overwritten!), but Daminion shows both keywords, TEST-JPG and TEST-RAW, combine them from different areas.
When I copied keywords in opposite direction, from jpg to raw - again, only IPTC has been updated, copied only TEST-RAW keyword from previously updated jpeg.
Thus, from Daminion point of view there is no new tags, it shows me the same list as before. Also, keywords duplication in RAW's IPTC is because my play with "-keywords+<keywords" vs just -keywords.

Are there any way to copy all these keywords locations respectively from one file to another? Or read them all but insert only into IPTC?

It became so complicated, I have to oversleep with this new (for me) knowledge to understand what exactly I would like to do now :-).

P.S. seems like if I will do with "-keywords+<keywords", as you've suggested before, I should have required result working only with IPTC. Will try tomorrow.


Phil Harvey

Quote from: SergeS on July 22, 2018, 10:42:55 PM
when I have copied keywords first time, from raw to jpg - only IPTC has been updated (overwritten!), but Daminion shows both keywords, TEST-JPG and TEST-RAW, combine them from different areas.

Yes.  I thought this may be the case.

You need to copy the keywords to each of the tags you want (not just "Keywords", but also "XPKeywords" and "Subject" tags, etc).
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

SergeS

Quote from: Phil Harvey on July 23, 2018, 07:34:14 AM
You need to copy the keywords to each of the tags you want (not just "Keywords", but also "XPKeywords" and "Subject" tags, etc).

Can you show some sample how to do it?

Phil Harvey

It depends on exactly what you want to copy where.  I already showed you how to add all Keywords: "-keywords+<keywords"

Assuming the destination tag (DESTTAG) is a list, the general format to add to the list is: "-DESTTAG+<SOURCETAG"

You may add as many of these arguments to the command as you want:

exiftool -tagsfromfile SOURCEFILE "-DESTTAG1+<SOURCETAG1" "-DESTTAG2+<SOURCETAG2" ... FILEorDIR

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

SergeS

Quote from: Phil Harvey on July 23, 2018, 10:06:23 AM
It depends on exactly what you want to copy where.  I already showed you how to add all Keywords: "-keywords+<keywords"

Assuming the destination tag (DESTTAG) is a list, the general format to add to the list is: "-DESTTAG+<SOURCETAG"

You may add as many of these arguments to the command as you want:

exiftool -tagsfromfile SOURCEFILE "-DESTTAG1+<SOURCETAG1" "-DESTTAG2+<SOURCETAG2" ... FILEorDIR

- Phil

Aha, so instead of "keywords" i can use "XPKeywords" or/and "Subject"? :-)
Got it, thank you. I thought "keywords" in a command-line switch with fixed name, I did not realized it is actually tag name.

SergeS

When using "-keywords+<keywords" approach to combine keywords from both files, are there any way to avoid writing of duplicates?
--a option does not help.

Phil Harvey

This is explained in FAQ 17.  Basically, you remove them first before adding them:

"-keywords-<keywords" "-keywords+<keywords"

However, if the keywords may contain duplicates before you start, then it would be a bit more involved.  Hopefully this isn't the case.

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

SergeS

Thank you so much!

p.s. Unbelievable! There is a option for any single wish :-). Thank you again.