Image folder/directory > description ?

Started by kaotikkeith, April 11, 2024, 11:05:58 AM

Previous topic - Next topic

kaotikkeith

Hi,
I have a folder structure like this:
Photos\2015\2015-03 Spring break\pic1.jpg...pic2.jpg...pic3.jpg
Photos\2015\2015-07 Summer Vacation\[images]
Photos\2015\2015-12 Christmas\[images]
Photos\2016\2016-01 Ski Trip\[images]
...and so on.

I am looking to grab the directory/folder name for each image and put it in the description tag (because this is carried into the Caption field when I drop them into iCloud/iOS photos). I do not want the directory-tree, only the folder containing said image. So in my hierarchy above, pic1, pic2, and pic3 would all have description metadata of "2015-03 Spring break".

I will be doing this from Windows command line, and would run it from the Photos directory, recursively.
I have tried the following:
exiftool -r "-description<directory" .
However, that gives me a description inclusive of the folder structure, resulting in "./2015/2015-03 Spring break"
How can I only grab the single folder name holding the image?

Also... I also have some images in Canon RAW - .CR2.  Any way to do the same thing with those files?

Thanks for any help!
-Keith

StarGeek

Try this in CMD (not PowerShell)
exiftool "-Description<${FilePath;$_=(split m(/),$_)[-2]}" /path/to/files/

This splits the absolute file path into an array and takes the second entry from the end. The first entry from the end [-1] would be the filename, the second [-2] is the parent directory, the third [-3] would be the next parent up, etc.

This will overwrite any data that already exists in Description and would require a more complicated command to preserve pre-existing data.

Quote from: kaotikkeith on April 11, 2024, 11:05:58 AMAlso... I also have some images in Canon RAW - .CR2.  Any way to do the same thing with those files?

I'm not sure what you mean.  Exiftool will process both CR2 and JPG files automatically.
"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