ExifTool Forum

ExifTool => Newbies => Topic started by: daniello on January 06, 2020, 11:22:28 AM

Title: Append string to filename if tag exists
Post by: daniello on January 06, 2020, 11:22:28 AM
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
Title: Re: Append string to filename if tag exists
Post by: StarGeek on January 06, 2020, 11:27:17 AM
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.
Title: Re: Append string to filename if tag exists
Post by: daniello on January 06, 2020, 11:57:15 AM
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
Title: Re: Append string to filename if tag exists
Post by: Phil Harvey on January 06, 2020, 12:29:28 PM
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

Title: Re: Append string to filename if tag exists
Post by: StarGeek on January 06, 2020, 12:32:38 PM
Are you running the command in a Windows BAT file?  If so, see FAQ #27 (https://exiftool.org/faq.html#Q27).

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 (https://exiftool.org/exiftool_pod.html#w-EXT-or-FMT--textOut) for details.
Title: Re: Append string to filename if tag exists
Post by: daniello on January 06, 2020, 11:55:05 PM
@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!
Title: Re: Append string to filename if tag exists
Post by: daniello on January 07, 2020, 12:25:36 AM
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.
Title: Re: Append string to filename if tag exists
Post by: StarGeek on January 07, 2020, 12:52:26 AM
See Common Mistake #5c (https://exiftool.org/mistakes.html#M5).

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 (https://exiftool.org/exiftool_pod.html#w-EXT-or-FMT--textOut) 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 (https://exiftool.org/exiftool_pod.html#p-FMTFILE-or-STR--printFormat).

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"
Title: Re: Append string to filename if tag exists
Post by: daniello on January 07, 2020, 01:40:08 AM
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
Title: Re: Append string to filename if tag exists
Post by: Phil Harvey on January 07, 2020, 07:05:00 AM
See the last section of FAQ 15 (https://exiftool.org/faq.html#Q15)
Title: Re: Append string to filename if tag exists
Post by: daniello on January 07, 2020, 07:59:07 AM
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.
Title: Re: Append string to filename if tag exists
Post by: Phil Harvey on January 07, 2020, 08:14:50 AM
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