ExifTool Forum

ExifTool => Newbies => Topic started by: Pineapple on February 27, 2020, 11:30:36 AM

Title: Is it possible to automatically create keywords based on directory location
Post by: Pineapple on February 27, 2020, 11:30:36 AM
I would like to automatically generate keywords into the metadata based on the folder the respected images are located in. For files located in Subfolders a keyword hierarchy should be created.

Would this be possible with Exif?
Title: Re: Is it possible to automatically create keywords based on directory location
Post by: Phil Harvey on February 27, 2020, 11:35:28 AM
A basic command to do this could be:

exiftool "-subject<directory" -sep "/" -r DIR

Here I am assuming you want to write the keywords to the XMP:Subject tag.

- Phil
Title: Re: Is it possible to automatically create keywords based on directory location
Post by: Pineapple on February 27, 2020, 05:41:46 PM
Thanks for your feedback. I am looking to update the "Keywords - Application2 (lptc)" field so that is picked up and can be managed in Lightroom Classic.

Would that work?

Title: Re: Is it possible to automatically create keywords based on directory location
Post by: StarGeek on February 27, 2020, 07:42:37 PM
Yes, Subject is where Lightroom will look for keywords.
Title: Re: Is it possible to automatically create keywords based on directory location
Post by: Pineapple on February 28, 2020, 08:05:56 AM
I am getting the following error message after running the command on a specific file [/quote]

C:\Program Files (x86)\Daminion Software\Daminion>"C:\Program Files\EXIF\exiftool.exe" -subject Test import\TestFolder\TestSubFolder\DSC04862.JPG" 0<directory" -sep "/" -r DIR"\\DESKTOP-Q6DIS7K\Users\henkv\Pictures\Edilon
The system cannot find the path specified.
Title: Re: Is it possible to automatically create keywords based on directory location
Post by: Phil Harvey on February 28, 2020, 08:10:19 AM
What is this in your command?:

import\TestFolder\TestSubFolder\DSC04862.JPG" 0<directory"

also, this is completely wrong

DIR"\\DESKTOP-Q6DIS7K\Users\henkv\Pictures\Edilon

Maybe try this command instead:

"C:\Program Files\EXIF\exiftool.exe" -subject -sep "/" -r "\\DESKTOP-Q6DIS7K\Users\henkv\Pictures\Edilon"

or maybe

"C:\Program Files\EXIF\exiftool.exe" -subject -sep "/" "Test import\TestFolder\TestSubFolder\DSC04862.JPG"

- Phil
Title: Re: Is it possible to automatically create keywords based on directory location
Post by: Pineapple on March 04, 2020, 12:03:54 AM
I managed to get it to work and used the following on a test image:

C:\Windows>exiftool "-subject<directory" -sep "/" -r C:/Users/henkv/Desktop/TestSubFolderDesktop/TestDesktopDSC04862.JPG

The keywords are created as individual keywords NOT as a hierarchy. Would you be able to help with that?

Thx, Henk
Title: Re: Is it possible to automatically create keywords based on directory location
Post by: Pineapple on March 04, 2020, 12:21:20 AM
Enclosed a screen shot
Title: Re: Is it possible to automatically create keywords based on directory location
Post by: StarGeek on March 04, 2020, 12:50:31 AM
Do you want the full directory path, i.e C:/Users/henkv/Desktop/TestSubFolderDesktop/ to be the hierarchy or just part of it?

If the full path, try this
exiftool "-HierarchicalSubject<${Directory;s(/)(|)g}" -r C:/Users/henkv/Desktop/TestSubFolderDesktop/TestDesktopDSC04862.JPG

That will create this hierarchy
C:
   Users
      henkv
         Desktop
            TestSubFolderDesktop
Title: Re: Is it possible to automatically create keywords based on directory location
Post by: Pineapple on March 04, 2020, 08:54:42 AM
That works really well!   :)

I would actually only need just a part of the hierarchy so I guess I just cut it out of: -r C:/Users/henkv/Desktop/TestSubFolderDesktop/TestDesktopDSC04862.JPG.   eg I am looking for TestSubFolderDesktop onwards plus potentially any subdirectories in that folder.

Is it possible to write the information directly on the file instead of a sidecar. And advise what the pros and cons are.  I need to work on 300K images to put in in perspective so doubling the quantity of files will be significant.

Thanks very much for your help.
Title: Re: Is it possible to automatically create keywords based on directory location
Post by: Phil Harvey on March 04, 2020, 08:57:17 AM
You can start from whatever directory level you want by "cd"-ing into that directory and running the command from there using a relative path.

- Phil
Title: Re: Is it possible to automatically create keywords based on directory location
Post by: Pineapple on March 04, 2020, 09:51:54 AM
Thanks..

Can you aslo let me know if it is possible to write the information directly on the file instead of a sidecar. And advise what the pros and cons are.  I need to work on 300K images to put in in perspective so doubling the quantity of files will be significant.

Henk
Title: Re: Is it possible to automatically create keywords based on directory location
Post by: Phil Harvey on March 04, 2020, 09:56:13 AM
Hi Henk,

Are these all JPG files?  If so, you should write the metadata directly to the file.

- Phil
Title: Re: Is it possible to automatically create keywords based on directory location
Post by: Pineapple on March 04, 2020, 10:49:33 AM
Hi Phil,

Thanks for that. All the images are .jpg... would you be able to let me know what the script should be in that case... I am a bit of a novice and not sure how to do that and really appreciate your guidance.

Henk
Title: Re: Is it possible to automatically create keywords based on directory location
Post by: Phil Harvey on March 04, 2020, 10:54:53 AM
Hi Henk,

All of the commands mentioned in this thread will write metadata to the original image.

- Phil
Title: Re: Is it possible to automatically create keywords based on directory location
Post by: StarGeek on March 04, 2020, 11:09:04 AM
If you change your directory to the top of your hierarchy, I'd suggest changing the Directory part to this
${Directory;s(^\./?)();s(/)(|)g}

That will drop the leading .| from the hierarchy.  Any files actually in the directory you start from will not have a hierarchy added.
Title: Re: Is it possible to automatically create keywords based on directory location
Post by: Pineapple on March 10, 2020, 07:27:55 AM
Hi,

I am getting many Warnings: eg "Warning: Error rebuilding maker notes (may be corrupt)" but there are several others as well. Can you let me know how/where I build -F into the script to fix these and/or -m to ignore minor errors. Or should I approach it in a different way.

Many thanks,

Henk

Title: Re: Is it possible to automatically create keywords based on directory location
Post by: Phil Harvey on March 10, 2020, 08:30:40 AM
Hi Henk,

FAQ 15 (https://exiftool.org/faq.html#Q15) discusses makernote warnings.  You can put -F or -m anywhere in the command should you decide to use them.

- Phil
Title: Re: Is it possible to automatically create keywords based on directory location
Post by: Pineapple on March 12, 2020, 10:14:23 PM
I am running into the issue that the keywords are not visible in Lightroom (mac) after I have refreshed they metadata "Read Metadata from File". However if I import the file again then Lightroom does pick up the keywords?!?!

I thought perhaps the fact that a new file is created by the exiftool command could be the reason and I included "-overwrite_original_in_place" and tried the following:

exiftool "-HierarchicalSubject<${Directory;s(/)(|)g}" -r -overwrite_original_in_place "D:\Foto Test\Foto\IMG_1957.jpg"

Eventhough the command does not create a new file, the keyword is still not visible after metadata-refresh in Lightroom.

Please note that I am running the latest Exiftool on a MS Surface/Windows 10 and the file is on an external HDD. After updating I connect it to iMac and Lightroom Classic (Mac)

Let me know if you can help. Thx

Henk
Title: Re: Is it possible to automatically create keywords based on directory location
Post by: Phil Harvey on March 13, 2020, 07:11:59 AM
Hi Henk,

First, on Mac you must use single quotes instead of double quotes around arguments containing a "$".  Are you sure your HierarchicalKeywords were written?

I tried this on LR 5.7.1 for Mac, and the HierarchicalKeywords written by ExifTool do show up for a JPG image after I do "Read Metadata from File".

- Phil
Title: Re: Is it possible to automatically create keywords based on directory location
Post by: Pineapple on March 13, 2020, 08:05:20 AM
Hi Phil,

Please note that I have used Exiftool on Windows to update the metadata of the file which resides on an external HDD. On Mac I am using Adobe Photoshop Lightroom Classic 9.1 for Mac.

I double checked in the command promt (windows) and can confirm that the metadata field Hierarchical Subject on the specific file is updated.  The keyword is visible in LR Mac only after importing it. Refresh does not work.

Regards,

Henk
Title: Re: Is it possible to automatically create keywords based on directory location
Post by: Phil Harvey on March 13, 2020, 08:07:21 AM
Hi Henk,

OK.  This seems like an LR 9.1 problem since it works with LR 5.7.1.  I suggest submitting this as a bug report to Adobe.

- Phil
Title: Re: Is it possible to automatically create keywords based on directory location
Post by: Pineapple on March 13, 2020, 12:36:40 PM
Hi Phil,

I have been in touch with Adobe and they asked me to submit a video demonstrating the issue. They also asked me to test it with another Meta data editing software which I did. I used AnalogExif and added a hierachical keyword, which it wrote to the Subject field and subsequently the refresh in LR did pick up the keyword hierarchy.

Changing the code in Exiftool to Subject instead of HierarchicalSubject did the trick as well.

exiftool "-Subject<${Directory;s(/)(|)g}" -r

At least I have a solution! Can you let me know if there is a more efficient/faster way to copy the info from "Hierarchical Subject" to "Subject" then the above script.  I need to do several 100K images so I would like the most efficient way.

Can you also let me know if it is worth addressing with Adobe that they are not picking up the "Hierarchical Subject" field during are refresh?

The Adobe engineer did mention that LR 5.7.1 is a completely different package than 9.2 (the current version)

Regards,
Henk
Title: Re: Is it possible to automatically create keywords based on directory location
Post by: Phil Harvey on March 13, 2020, 01:05:25 PM
Hi Henk,

To set Subject from HierarchicalSubject, do this:

exiftool "-subject<hierarchicalsubject" -r DIR

- Phil