Create Keywords in Lightroom Classic based on folder location

Started by GSC, July 21, 2024, 07:53:16 PM

Previous topic - Next topic

GSC

From the start, I'm not a programmer. I am looking for a way to provide keywords based on the containing folders. Thus:

In a USA folder, there would be a California folder; in that, there'd be a Los Angeles folder; in that folder, there would be a San Diego Zoo folder, a Los Angeles Zoo folder, and a San Francisco Zoo folder.

What I want to see in the Keyword metadata for any files in these folders, one would see:

USA, California, Los Angeles, San Diego Zoo
USA, California, Los Angeles, Los Angeles Zoo
USA, California, Los Angeles, San Francisco Zoo

I can do this manually, but I've got thousands of files. I'm hoping that this can be done software-wise, but, as stated, I am not a programmer. Can anyone help me?

For the record, I'm on a Mac.

Phil Harvey

Something like this will do:

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

where DIR is the root directory (folder) and the first word you want in the keywords.  To do this, you should first "cd" into the directory above this.  For example:

cd ~/Pictures

Then DIR would be "USA" for only the USA pictures, or "*" for everything in that folder.

The -sep "/" splits the string into individual keywords using "/" as a separator.

Notice I'm writing XMP Subject instead of IPTC Keywords because the old IPTC IIM format is being phased 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 ($).

GSC

Hi Phil.

Thank you. As I stated, I am a rank beginner on any kind of coding. I thank you for your code, but I have no idea what to put in, where to put that into Lightroom Classic, or how to enter it.

Do I do that for each image? For each folder? How? Where?

Sorry to bother you, but this is as new to me as my profession was to many, many people. (For over 40 years, I was a scientific glassblower. I made the custom glass apparatus used in laboratories for their research.)

Phil Harvey

I don't know where LightRoom classic keeps its files.  As well, it is likely that LR won't pick up any metadata changes unless you re-import the files.  So I don't know what is best for you.

I don't know how to be more clear than the instructions I gave (the command I gave will update all images at once), but this applies to unencumbered image files.  But things are bound to be different for images already imported into LightRoom.

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

StarGeek

Quote from: GSC on July 22, 2024, 06:07:25 PMAs I stated, I am a rank beginner on any kind of coding. I thank you for your code, but I have no idea what to put in, where to put that into Lightroom Classic, or how to enter it.

You don't use it in Lightroom. What Phil listed is a command for the command line. In the case of Mac, that would be Terminal.

QuoteDo I do that for each image? For each folder? How? Where?

Where Phil listed "DIR", you can put the full path to any number of directories. If you CD to the parent directory of USA, then you would use a dot . to process all files in that directory and the ones below it.

Take note that this is not coding, it's running a command on the command line. You might want to search for some tutorials on using the Mac Terminal.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

GSC

Hi StarGeek,

Thanks for adding your suggestions for use. This gives me a handle on where and what will be taking place. Since this will take place outside of Lightroom, I know that after this processing, I will need to do a "synchronizing" of the images. One of the dynamics of LRC is that it is a database, and everything that occurs outside of working within LRC is unknown to LRC (E.g., working the finder or Explorer). I will need to do some testing to verify the best way to update the catalog.

And thank you again, Phil, for some of the basics.