News:

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

Main Menu

Append string to filename if tag exists

Started by daniello, January 06, 2020, 11:22:28 AM

Previous topic - Next topic

daniello

Hi, I am looking for a way to differentiate between my phones stock cam pictures and those of a google cam mod I use. The only way obvious to me is the XPComment Exif tag that only exists when pictures are taken with stock cam. The tag itself contains chinese characters which cause hickups in another tool I sometimes use - but generally I don't care about the tag's content.

All I'd need to facilitate is to append a "stock" string to the file name when XPComment as such exists.

Is this something ExifTool can to? Could someone point out a command line off the top of the head, that I could fire at a folder?

Cheers,
daniello

StarGeek

To test it out first, try this
exiftool -if "$XPComment" "-Testname=%f Stock.%e" /path/to/Dir

This will list what filename changes exiftool would make to a directory.  If the output looks correct, change Testname to Filename.

Make sure and don't run it multiple times on a directory though, otherwise you'll end up with multiple "Stock"s in the filename.
* 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).

daniello

Simulation gave me warnings (file would exist) and this summary:
1110 files failed condition
    0 image files updated
  327 image files unchanged

Looked good to me.

Run with "Filename" gave errors but renamed nothing .. I have one file named "e" (which I can recover).
Error: 'd:/2020-01-06 Sri Lanka/Daniel/e' already exists

Phil Harvey

If all files failed the condition, then XPComment didn't exist in the files (or was empty, or had the value "0").  Try this on a single file that you think should have XPComment to see what Exiftool finds:

exiftool -xpcomment FILE

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

StarGeek

Are you running the command in a Windows BAT file?  If so, see FAQ #27.

Otherwise, something is wrong, as that command shouldn't rename something to just "e".

To avoid naming collisions, you can add %c to add a copy number for duplicates. See the -w (textout) option for details.
* 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).

daniello

@Phil

My interpretation of the summary was that 327 images did contain the tag (and remained unchanged due to simulation) and 1110 did. Sums up to the total amount of images. That's why it looked fine to me.

@StarGeek

Thanks .. that fixed it. with double %% it works!

daniello

In a very similar scenario I would now like to add tag contents to the filename. The tag is called "Software":

exiftool -if "$Software" "-Testname=%%f %%$Software.%%e" "d:\2020-01-06 Sri Lanka\Daniel\gcam\*.jpg"

I assume it something this easy but the variations I had tried don't work. I read about the -tagsFromFile parameter but I don't know if this is what I need to deal with.

StarGeek

See Common Mistake #5c.

In this case you are copying a tag to another tag, not assigning a static value.  So you have to change the equal sign = to a Less/Greater Than sign (< or >). 

Additionally, you have superfluous percent signs.  The percent signs are only used with the special variables such as the %f and %e.  See the -w (textout) option for details.

You may have to add braces to $Software to prevent exiftool from thinking what follows afterwards is part of the tag name.  See the -p (printFormat) option.

So try (braces may be unnecessary, I haven't tested it)
exiftool -if "$Software" "-Testname<%%f ${Software}.%%e" "d:\2020-01-06 Sri Lanka\Daniel\gcam\*.jpg"
* 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).

daniello

thanks .. it seems to work with and without braces.

There is a warning though in both runs:
Warning: [minor] Unrecognized MakerNotes

d:/2020-01-06 Sri Lanka/Daniel/gcam/2019-12-28 11.35.30_daniel.jpg' --> 'd:/2020-01-06 Sri Lanka/Daniel/gcam/2019-12-28 11.35.30_daniel HDR+ 1.0.276119539zdh.jpg'
Warning: [minor] Unrecognized MakerNotes - d:/2020-01-06 Sri Lanka/Daniel/gcam/2019-12-28 11.35.40_daniel.jpg

Phil Harvey

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

daniello

Thanks .. I'm good now .. everything worked out well .. all I need now is motivation for sorting all pictures ;-)

I didn't find how to attach a [Solved] to the title.

Phil Harvey

Quote from: daniello on January 07, 2020, 07:59:07 AM
I didn't find how to attach a [Solved] to the title.

exiftool "-title<$title [Solved]" FILE

hehe (joke)

...but seriously, the forum is configured to not allow editing of posts after 12 hours, so it is generally not possible to edit the title of the first post in a topic.

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