Is it possible to automatically create keywords based on directory location

Started by Pineapple, February 27, 2020, 11:30:36 AM

Previous topic - Next topic

Pineapple

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?

Phil Harvey

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
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Pineapple

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?


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).

Pineapple

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.

Phil Harvey

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
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Pineapple

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

Pineapple


StarGeek

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
* 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).

Pineapple

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.

Phil Harvey

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
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Pineapple

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

Phil Harvey

Hi Henk,

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

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

Pineapple

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

Phil Harvey

Hi Henk,

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

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