ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: napiwn on September 01, 2021, 02:25:50 AM

Title: Multiple adding to jpg files tags from folder name
Post by: napiwn on September 01, 2021, 02:25:50 AM
For several years I have been sorting jpg files according to the scheme, for example:

C: \ Album \ 2016 \ 2016-01-02 uncle's birthday

C: \ Album \ 2016 \ 2016-03-03 vacation

C: \ Album \ 2021 \ 2021-06-01 a trip to the seaside

There are a lot of jpg files, the names of the folders contain a lot of information about the photos. When I was creating my archive, photo tagging wasn't popular. Now I'd like to find a quick way to tag all photos in folders with folder names. Folder names are sometimes very long, words are sometimes separated by "_", sometimes with a space. However, it is not a problem to sit for a dozen or so hours and improve the namefolder. Manually tagging photos is much longer.

Is it possible to organize photos?
Title: Re: Multiple adding to jpg files tags from folder name
Post by: StarGeek on September 02, 2021, 12:45:40 PM
It definitely can be done but it all depends upon the folder names.  Are there additional subdirectories?  Is the formatting similar or inconsistant, i.e. are some folders Month-Day-Year, while others are Year-Month-Day?

Also, where do you want to put the data?

Assuming you want to add the folder names as a keyword, with the date as ####-##-## and then a space before the actual data, you could do this
exiftool "-Subject<${Directory;s/.*\/([^\/]*$)/$1/;s/\d{4}-\d\d-\d\d\s*//;s/_/ /}" /path/to/files/

This takes the directory name, strips off all directories except the last one, strips off the date, and then changes any underscores into spaces.

You have to provide a path to the directory to process.  You can't CD into that directory and run this command with a * or .  For example, you can't CD into C:\Album\2016\2016-01-02 uncle's birthday\ and run
exiftool "-Subject<${Directory;s/.*\/([^\/]*$)/$1/;s/\d{4}-\d\d-\d\d\s*//;s/_/ /}" *

Instead you would run
exiftool "-Subject<${Directory;s/.*\/([^\/]*$)/$1/;s/\d{4}-\d\d-\d\d\s*//;s/_/ /}"  "C:\Album\2016\2016-01-02 uncle's birthday"

This command creates backup files.  Add -Overwrite_Original (https://exiftool.org/exiftool_pod.html#overwrite_original) to suppress the creation of backup files.  Add -r (https://exiftool.org/exiftool_pod.html#r-.--recurse) to recurse into subdirectories.
Title: Re: Multiple adding to jpg files tags from folder name
Post by: napiwn on October 19, 2021, 05:06:56 AM
I tried to follow the instructions, but there are errors, e.g. file opening error, files weren't updated due to errors. I am asking for help, which code should be entered.
Title: Re: Multiple adding to jpg files tags from folder name
Post by: Phil Harvey on October 19, 2021, 07:29:19 AM
Can you tell us exactly what the error messages were?

- Phil
Title: Re: Multiple adding to jpg files tags from folder name
Post by: napiwn on October 19, 2021, 05:19:06 PM
Thank you for the quick reply. I was able to tag a photo in a folder using the command :

exiftool "-Subject<${Directory;s/.*\/([^\/]*$)/$1/;s/\d{4}-\d\d-\d\d\s*//;s/_/ /}"  "C:\Album\2016\2016-01-02 uncle's birthday"

1. Can the command be applied to, for example, 2016 subfolders? What does the command look like.

2. What does the command look like without creating jpg_original?

3. If I separate the words ";" there will be separate tags in the folder name?

4. Or, instead of adding a tag, add a photo caption. Similarly, add the photo caption field. What the command looks like.
Title: Re: Multiple adding to jpg files tags from folder name
Post by: StarGeek on October 19, 2021, 07:08:52 PM
Quote from: napiwn on October 19, 2021, 05:19:06 PM
1. Can the command be applied to, for example, 2016 subfolders? What does the command look like.

You would add the -r (-recurse) option (https://exiftool.org/exiftool_pod.html#r-.--recurse).  Though you might have to edit your regex expressions to deal with the subfolders properly.

Quote2. What does the command look like without creating jpg_original?

Add the -overwrite_original option (https://exiftool.org/exiftool_pod.html#overwrite_original)

Quote3. If I separate the words ";" there will be separate tags in the folder name?

I'm not sure what you mean by this, but your command as shown creates a single keyword.  To separate on a character, add the -sep option (https://exiftool.org/exiftool_pod.html#sep-STR--separator).

Quote4. Or, instead of adding a tag, add a photo caption. Similarly, add the photo caption field. What the command looks like.

The same, except you would change Subject to the tag you want to write to, most probably Description.  Read FAQ #3 (https://exiftool.org/faq.html#Q3).  Set the tag you want to change in whatever program you are using to see the description and then run the command in FAQ #3 to see what is written.  If you're viewing the data in Windows, see the Windows metadata (https://exiftool.org/forum/index.php?topic=6591.0) for details on what Windows reads.
Title: Re: Multiple adding to jpg files tags from folder name
Post by: PatrickHakvoort on January 24, 2023, 09:08:07 AM
I'm struggling to get the exiftool working. We have lots of folders containing .jpg-files. We want to add tags (subject) based on the foldername/structure the picture is in. The foldernames only contain words, so no dates or times. Each (recursive) foldername should be added as a tag to the image. What would the correct command be like?

Tried several command-options, also based on previous comments and instructions on this forum, but still doesn't seem to work.

Any help would be greatly appreciated.
Title: Re: Multiple adding to jpg files tags from folder name
Post by: StarGeek on January 24, 2023, 10:31:33 PM
See this post (https://exiftool.org/forum/index.php?topic=9537.msg49360#msg49360).

As it says, you'll want to CD to the directory directly above the first level that you want to use as a keyword.