I do not undewrstand how -if works

Started by OMU1994, February 18, 2025, 02:42:25 PM

Previous topic - Next topic

OMU1994

I use version 13.19 for windows 11. I have been using it and stumbled upon

Output from Powershell on Windows 11

PS V:\Bilder> exiftool  -DateTimeCreated -city -sub-location 2025\2025-02-07
======== 2025/2025-02-07/Ulm, Innere-Wall-Strasse, Schubart-Gymnasium mit Sternwarte 2025-02-07_2318.jpg
Date/Time Created              : 2025:02:07 13:22:38+01:00
City                            : Ulm
Sub-location                    : Innere-Wall-Strasse
    1 directories scanned
    1 image files read

Comment: the tags IPTC:City, IPTC:Sub-location  and DateTimeCreated exist

PS V:\Bilder> exiftool  -if "defined $City" -DateTimeCreated -city -sub-location 2025\2025-02-07
    1 directories scanned
    1 files failed condition
    0 image files read

In my humble opinion this should give the same output, since the Tag City exists

PS V:\Bilder> exiftool  -if "defined $IPTC:City" -DateTimeCreated -city -sub-location 2025\2025-02-07
    1 directories scanned
    1 files failed condition
    0 image files read

The same: In my humble opinion this should give the same output, since the Tag City exists


PS V:\Bilder> exiftool  -if "not defined $IPTC:City" -DateTimeCreated -IPTC:city -sub-location 2025\2025-02-07
======== 2025/2025-02-07/Ulm, Innere-Wall-Strasse, Schubart-Gymnasium mit Sternwarte 2025-02-07_2318.jpg
Date/Time Created              : 2025:02:07 13:22:38+01:00
City                            : Ulm
Sub-location                    : Innere-Wall-Strasse
    1 directories scanned
    1 image files read

This is most crazy: If I test for the non-Existence of an existing tag, it is shown.

Somehow this defies my understanding of boolean logic.

Yet another observation: Testing for the existence of a tag containing a hyphen does not work at all:
-if "defined $IPTC:Sub-location" seems to not work.

It would be nice if someone could help me sorting things out.

Thanks
Othmar

StarGeek

Don't use PowerShell. Use CMD. The quoting rules for PS are different than every other command line and what works on CMD with double quotes or Mac/Linux with single quotes sometimes doesn't work either way on PS. See this post.
"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

OMU1994