last directory name from the file path

Started by BeTePoK, March 17, 2024, 11:09:31 AM

Previous topic - Next topic

BeTePoK

I have several nested directories
c:/photos/2023/spain/2023 Barcelona/img_1.jpg
c:/photos/2023/spain/2023 Cullera/img_2.jpg
f:/photos/2024/Egypt/img_3.jpg
f:/photos/2021/Vietnam/img_4.jpg

I need to add the last directory name from the path to the -Title tag

How can I do that?

Phil Harvey

exiftool "-title<${directory;s(.*/)()}" ...

This uses the advanced formatting feature to remove everything up to and including the last "/" in the directory name, then copies that to the Title tag.

- 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

Note that this command requires that you have either CDed to a directory above the one you want to extract,
cd f:/photos/2024/
exiftool -r "-title<${directory;s(.*/)()}" .


or that you have used a absolute path to the directory
exiftool "-title<${directory;s(.*/)()}" f:/photos/2024/Egypt/


If you cd into f:/photos/2024/Egypt/ and run the command from there then Directory will only contain the dot
* 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).