ExifTool Forum

ExifTool => Newbies => Topic started by: BeTePoK on March 17, 2024, 11:09:31 AM

Title: last directory name from the file path
Post by: BeTePoK on March 17, 2024, 11:09:31 AM
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?
Title: Re: last directory name from the file path
Post by: Phil Harvey on March 19, 2024, 08:28:10 AM
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
Title: Re: last directory name from the file path
Post by: StarGeek on March 24, 2024, 04:12:32 PM
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