News:

2023-03-15 Major improvements to the new Geolocation feature

Main Menu

Recursively add keywords to files from parent directory name

Started by Tartopom3, June 01, 2014, 04:13:01 AM

Previous topic - Next topic

Tartopom3

Hi every exiftool's powerusers,

Since years i've been sorted my pictures in that way, a 'one level' directory structure, where these directories embeds keywords (separated by <space>):

<root_folder>/<keyword1 keyword2...>/file<1..n>.jpg

Today i would like to add those keywords (embedded in parent directory name) to my files with exiftool.
Do i need to write a script to parse recursively all my directories and affect tags or is it possible to get it on a single magical one-line with (the magical also) exiftool? In "such" a way

exiftool -sep " " -keywords-= "-keywords+=<parent directory name>" *.jpg

Thanks for any help or tip..
KR



Phil Harvey

To do this, you should first "cd" to the root folder, then apply this command:

exiftool -sep " " "-keywords+<directory" -ext jpg *

This is not what I would call recursive though, because it is a 1-level directory.  To recurse into deeper levels, the -r option may be added, but in this case some formatting of the directory name would be required to prevent the path separator ("/") from messing up the keywords.

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

Tartopom3

Thank you so much Phil for your fast reply...and congratulations to have offered us such a power tool!

Best regards from France

Tartopom3

Oh...i forgot to ask something

Can you confirm that

$ exiftool -sep " " -keywords-= "-keywords+<directory" -ext jpg *

will prevent files to be modified if they already have keywords?

Thanks in advance for any reply,
Best Regards

Phil Harvey

No.  The -= is not a conditional deletion for list-type tags.  It is used to delete individual keywords.  Instead, use -if "not $keywords" (use single quotes instead if you are on Mac or Linux).

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

Tartopom3

Thank you so much.

...would perhaps be worth to appear in the FAQ, no?

Thanks again,
Best regards
Paul

Phil Harvey

Hi Paul,

This is the first time I can recall anyone having this problem.

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