Author Topic: Recursively add keywords to files from parent directory name  (Read 3159 times)

Tartopom3

  • Newbie
  • *
  • Posts: 6
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

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 16885
    • ExifTool Home Page
Re: Recursively add keywords to files from parent directory name
« Reply #1 on: June 01, 2014, 07:00:12 AM »
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, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Tartopom3

  • Newbie
  • *
  • Posts: 6
Re: Recursively add keywords to files from parent directory name
« Reply #2 on: June 01, 2014, 11:08:22 AM »
Thank you so much Phil for your fast reply...and congratulations to have offered us such a power tool!

Best regards from France
 

Tartopom3

  • Newbie
  • *
  • Posts: 6
Re: Recursively add keywords to files from parent directory name
« Reply #3 on: June 01, 2014, 01:21:07 PM »
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

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 16885
    • ExifTool Home Page
Re: Recursively add keywords to files from parent directory name
« Reply #4 on: June 01, 2014, 02:05:10 PM »
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, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Tartopom3

  • Newbie
  • *
  • Posts: 6
Re: Recursively add keywords to files from parent directory name
« Reply #5 on: June 01, 2014, 02:23:15 PM »
Thank you so much.

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

Thanks again,
Best regards
Paul

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 16885
    • ExifTool Home Page
Re: Recursively add keywords to files from parent directory name
« Reply #6 on: June 01, 2014, 06:16:27 PM »
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, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).