Copy photos into folders based on keyword

Started by AmericanLoco, May 18, 2024, 11:49:33 AM

Previous topic - Next topic

AmericanLoco

Hi,

I have 200 photos I took at an event. The photos contain multiple people. I tagged the individuals in each photo using FastPhotoTagger (which actually uses exiftool).

Now, I'd like to send each person at this event a copy of every photo that contains them.

So I have my source directory with all of the photos in it. Each photo has the people tagged as a "Keyword" with the names separated with semicolons. I also have another directory full of empty folders, each folder named with the same names used in the tags.

So I'd like to copy my source images, into those named folders, based on the keywords.

For example, Photo001 might have the Keywords "Ronald; Wendy; Denny; Tim". I would like to copy Photo001 into my separate destination folders named "Ronald", "Wendy", "Denny" and "Tim". I want to do this to all ~200 photos in my source directory.

StarGeek

Quote from: AmericanLoco on May 18, 2024, 11:49:33 AMEach photo has the people tagged as a "Keyword" with the names separated with semicolons.

You need to figure the tag that holds the data. Use the command in FAQ #3 to figure out the exact tag name and group.

It sounds like it might be XPKeywords, as that saves tags as a semicolon separated string, but if the data instead appears in Subject or Keywords and is still semicolon separated, then the data has been incorrectly written to the files, as those tags are list type tags, where each entry is saved completely separate from the others.  Exiftool will output it as a CommaSpace separated string, but that isn't how they are saved internally.

But it will still be difficult to do.  It would require a shotgun approach similar to what was done here. It would also be useful to know what the maximum number of keywords used in a single file, but for that, the actual tag name is needed.
* 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).

AmericanLoco

I ran that command on an image that contains 3 keywords. In FastPhotoTagger, I input the keywords as "Alice; Bobby; Carl"

exiftools using -a -G1 -s reports this
[IPTC]          Keywords                        : Alice, Bobby, Carl

greybeard

If you are running under MacOS or Linux you could combine exiftool and awk to generate the commands into a file and then run them (has the advantage that you can check the commands before they are run):

exiftool -T -FileName -sep " " -IPTC:Keywords -ext jpg . | awk '{split($0,a," "); for (key in a) { if (key > 1) {print "cp " a[1] " dir2/" a[key] }}}'

This version assumes there are no spaces in the file name or the keywords, all image files are jpg and the subdirectories exist in the dir2 directory (other assumptions could be catered for).

There are probably more elegant ways of achieving what you want.