String manipulation - Tag from filename

Started by Lasersec, July 27, 2015, 05:58:37 PM

Previous topic - Next topic

Lasersec

May I first of all thank Phil for his brilliant tool! But what a learning curve!

I have searched through the forums and although I can find similar answers, I cannot locate anything which precisely answers my query so I turn to the experts for advice.

My problem I believe is quite simple... I have a number of images where the filename of the image contains the names of people within the image and I want to extract only these to the Subject field.

Examples:   

Andy Dee Roger Paul (10).JPG
Peter Paul Mary (7).JPG

I would like to be able to strip out  (10).JPG & (7).JPG or similar configurations and just have the peoples names inserted within the subject field. I have been playing with this command line found on the forums...  exiftool "-subject<${filename;s/\.[^.]*$//}" -r DIR -P which seems to work ok but I just cannot work out how to strip out the numeric and brackets portion of the filename prior to inserting within the chosen subject field.

Any help would be greatly appreciated.


StarGeek

Try
ExifTool -r -P "-subject<${filename;s/ *\(.*//}" DIR

Take note that there is a space just before the first asterisk.  That will strip out the space(s) between the last letter and the first paren.  As always, test it out before running over your main files.

The part after "filename" is a regular expression (regex).  Check out Regular-expressions.info to learn more about how to use them.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Lasersec

Many thanks StarGeek... You definitely are a Star!.

I have to admit on being a newbie with this stuff, but I note your comment and shall take a look at Regular-expressions.info and see if I can get my head around some of the complexities of syntax.

In the meantime, your response worked perfectly and as expected removed the (numeric value).JPG. However, I forgot to include in my original query that some of my files don't have the (numeric value).JPG in the filename. Joe Bloggs.JPG gets saved with it's extension. What changes would be needed to your syntax to overcome this effect?

StarGeek

I'm sure there's a better way to do this, but my brain doesn't seem want to deal with it now, so I'm doing two substitutions.

ExifTool -r -P "-subject<${filename;s/\.[^.]*$//;s/ *\([^\(]*$//}" DIR

The first regex is from your post, and strips away any extension.  The second part strips away anything from the last open paren.

c:\>exiftool -P  -overwrite_original -progress "-subject<${filename;s/\.[^.]*$//;s/ *\([^\(]*$//}" X:\!temp\z
======== X:/!temp/z/Andy Dee Roger Paul (10).JPG [1/2]
======== X:/!temp/z/Joe Bloggs.JPG [2/2]
    1 directories scanned
    2 image files updated

c:\>exiftool -subject X:\!temp\z
======== X:/!temp/z/Andy Dee Roger Paul (10).JPG
Subject                         : Andy Dee Roger Paul
======== X:/!temp/z/Joe Bloggs.JPG
Subject                         : Joe Bloggs
    1 directories scanned
    2 image files read


Though I just realized you're using subject as your target tag.  This will insert the data as a single entry.  For example, the first file will have one entry with "Andy Dee Roger Paul".  If you want each name to be a separate entry, "Andy", "Dee", "Roger", "Paul", then you'll have to add -sep " "

c:\>exiftool -P  -overwrite_original -progress "-subject<${filename;s/\.[^.]*$//;s/ *\([^\(]*$//}" X:\!temp\z -sep " "
======== X:/!temp/z/Andy Dee Roger Paul (10).JPG [1/2]
======== X:/!temp/z/Joe Bloggs.JPG [2/2]
    1 directories scanned
    2 image files updated

c:\>exiftool -subject X:\!temp\z
======== X:/!temp/z/Andy Dee Roger Paul (10).JPG
Subject                         : Andy, Dee, Roger, Paul
======== X:/!temp/z/Joe Bloggs.JPG
Subject                         : Joe, Bloggs
    1 directories scanned
    2 image files read


Though this will become much more complex if you have first and last names or even a mix of just first and first last names.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype