News:

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

Main Menu

Multiple adding to jpg files tags from folder name

Started by napiwn, September 01, 2021, 02:25:50 AM

Previous topic - Next topic

napiwn

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?

StarGeek

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 to suppress the creation of backup files.  Add -r to recurse into subdirectories.
* 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).

napiwn

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.

Phil Harvey

Can you tell us exactly what the error messages were?

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

napiwn

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.

StarGeek

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.  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

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.

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.  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 for details on what Windows reads.
* 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).

PatrickHakvoort

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.

StarGeek

See this post.

As it says, you'll want to CD to the directory directly above the first level that you want to use as a keyword.
* 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).