[Solved:cause I use -d] Test with -if behaves not the same when read or write ?

Started by exiftewb, July 27, 2017, 05:34:09 AM

Previous topic - Next topic

exiftewb

Hi
First, many thanks for this great tool !
I have to rename a lot a files by prefixing names with the CreateDate tag after I set the missing -alldates.
I yet moved all files in a .../DD dir
In each same dir are also files with correct date tags that are yet renamed.
Then on each dir I ran, for example in dir 13
$ exiftool -AllDates='2012:05:13 00:00:00' -overwrite_original_in_place -P -m 13/E7*OK
Then I compare badly-tagged files to good ones to find the correct TIME and when one or more is done, for each I run e.g.
$ exiftool -AllDates+='0:0:0 17:18:19' -overwrite_original_in_place -P -m 13/E79\ MAY\ 125.jpg
exiftool "-FileName<CreateDate" -overwrite_original_in_place -P -m -d %Y%m%d_%H%M%S-ml-%%.25lf%%-2nc.%%le 13/E79\ MAY\ 125.jpg
OK, ending in file renamed 20120513_171819-ml-125.jpg
Now fed up with the need to adapt the rename each command line according to the set tag one(s) I had the idea to use -if so that rename only runs on files with time tag part is different than 00:00:00
Unfortunately, all files are renamed, yet OK-tagged ones fine, but others end in 20120513_000000-ml-NuMbEr.jpg
Below is my report. Please what do I do wrong ? Thank you
$ exiftool -ver
9.46

$ exiftool -CreateDate -if '$CreateDate ne "2012:05:13 00:00:00"' 13/E7900_ROME\ 9-13\ MAI\ 2012\ 4*
   17 files failed condition

$ exiftool -CreateDate -if '$CreateDate eq "2012:05:13 00:00:00"' 13/E7900_ROME\ 9-13\ MAI\ 2012\ 4*
======== 13/E7900_ROME 9-13 MAI 2012 451.jpg
Create Date                     : 2012:05:13 00:00:00
...
======== 13/E7900_ROME 9-13 MAI 2012 488.jpg
Create Date                     : 2012:05:13 00:00:00
   17 image files read

$ exiftool -CreateDate -if '$CreateDate eq "2012:05:13 00:00:0"' 13/E7900_ROME\ 9-13\ MAI\ 2012\ 4*
   17 files failed condition

$ exiftool -AllDates+='0:0:0 7:10:23' -overwrite_original_in_place -P -m 13/E7900_ROME\ 9-13\ MAI\ 2012\ 451.jpg
    1 image files updated

$ exiftool -CreateDate -if '$CreateDate ne "2012:05:13 00:00:00"' 13/E7900_ROME\ 9-13\ MAI\ 2012\ 4*
======== 13/E7900_ROME 9-13 MAI 2012 451.jpg
Create Date                     : 2012:05:13 07:10:23
   16 files failed condition

$ exiftool "-FileName<CreateDate" -overwrite_original_in_place -P -m -d %Y%m%d_%H%M%S-ml-%%.25lf%%-2nc.%%le -if '$CreateDate ne "2012:05:13 00:00:00"' 13/E7900_ROME\ 9-13\ MAI\ 2012*
   17 image files updated

$ exiftool -CreateDate -if '$CreateDate ne "2012:05:13 00:00:00"' 13/*ml*
======== 13/20120513_071023-ml-451.jpg
Create Date                     : 2012:05:13 07:10:23
   16 files failed condition

$ exiftool -CreateDate -if '$CreateDate eq "2012:05:13 00:00:00"' 13/*ml*
======== 13/20120513_000000-ml-452.jpg
Create Date                     : 2012:05:13 00:00:00
...
======== 13/20120513_000000-ml-488.jpg
Create Date                     : 2012:05:13 00:00:00
    1 files failed condition
   16 image files read

... (hand rename back 16 files)

$ ls 13/E7900_ROME\ 9-13\ MAI\ 2012\ 45*
13/E7900_ROME 9-13 MAI 2012 452.jpg  ...  13/E7900_ROME 9-13 MAI 2012 458.jpg

$ exiftool -CreateDate -if '$CreateDate eq "2012:05:13 00:00:00"' 13/E7900_ROME\ 9-13\ MAI\ 2012\ 45*
======== 13/E7900_ROME 9-13 MAI 2012 452.jpg
Create Date                     : 2012:05:13 00:00:00
...
======== 13/E7900_ROME 9-13 MAI 2012 458.jpg
Create Date                     : 2012:05:13 00:00:00
   6 image files read

$ exiftool -CreateDate -if '$CreateDate ne "2012:05:13 00:00:00"' 13/E7900_ROME\ 9-13\ MAI\ 2012\ 45*
   6 files failed condition

$ exiftool -AllDates+='00:00:00 07:10:24' -overwrite_original_in_place -P -m 13/E7900_ROME\ 9-13\ MAI\ 2012\ 452.jpg
   1 image files updated

$ exiftool -CreateDate 13/E7900_ROME\ 9-13\ MAI\ 2012\ 45*
======== 13/E7900_ROME 9-13 MAI 2012 452.jpg
Create Date                     : 2012:05:13 07:10:24
======== 13/E7900_ROME 9-13 MAI 2012 453.jpg
Create Date                     : 2012:05:13 00:00:00
...
======== 13/E7900_ROME 9-13 MAI 2012 458.jpg
Create Date                     : 2012:05:13 00:00:00
    6 image files read

$ exiftool -CreateDate -if '$CreateDate ne "2012:05:13 00:00:00"' 13/E7900_ROME\ 9-13\ MAI\ 2012\ 45*
======== 13/E7900_ROME 9-13 MAI 2012 452.jpg
Create Date                     : 2012:05:13 07:10:24
   5 files failed condition

$ exiftool -CreateDate -if '$CreateDate eq "2012:05:13 00:00:00"' 13/E7900_ROME\ 9-13\ MAI\ 2012\ 45*
======== 13/E7900_ROME 9-13 MAI 2012 453.jpg
Create Date                     : 2012:05:13 00:00:00
...
======== 13/E7900_ROME 9-13 MAI 2012 458.jpg
Create Date                     : 2012:05:13 00:00:00
   1 files failed condition
   5 image files read

... rename all 6 back and let's try again (without -m)

$ exiftool "-FileName<CreateDate" -overwrite_original_in_place -P -d %Y%m%d_%H%M%S-ml-%%.25lf%%-2nc.%%le -if '$CreateDate ne "2012:05:13 00:00:00"' 13/E7900_ROME\ 9-13\ MAI\ 2012\ 45*.jpg
    6 image files updated

?????

Phil Harvey

When you add the -d option, it affects the CreateDate you are testing in your -if.  To avoid this, you can test the unconverted value:

-if '$CreateDate# ne "2012:05:13 00:00:00"'

(here I added a "#" to disable the print conversion for CreateDate in the -if condition)

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

exiftewb

Thank you Phil, this does the job.
This is the 1st time I use this # noPrintConv thing
I understand now that when I ran the command against a single file, the -if ne always matched, nearly whatever I could have put in the quotes (only the FILE filtered the job). To get it work as is, could I have put the ugly -if '$CreateDate ne "20120512_000000-ml-%.25lf%-2nc.%le"' or if possible test -if '$CreateDate DoesNotBiginWith "20120512_000000"' ?
I found this string with exiftool -CreateDate -if '$CreateDate# eq "blablah"' . and tested it OK with no # suffix  & with ne ... and the ugly single matching blahblah  :P.
Now, if I was courageous, I'd give some tests with -n and no # suffix ....

Did I meet this difficulty because I use a specified date format for the rename when I test against a date tag ? Should I've test against any no date tag, I'd never see this ?
Is it possible my faulty command has corrupted tags in files I've already run it against?

Maybe it is worth to add some -if with -d example in a yet existing example in the rename section.

Thanks again man

Phil Harvey

Quote from: exiftewb on July 27, 2017, 04:36:06 PM
-if '$CreateDate DoesNotBiginWith "20120512_000000"' ?

This should work.

QuoteDid I meet this difficulty because I use a specified date format for the rename when I test against a date tag ?

Yes.

QuoteShould I've test against any no date tag, I'd never see this ?

I don't understand.

QuoteIs it possible my faulty command has corrupted tags in files I've already run it against?

No.

QuoteMaybe it is worth to add some -if with -d example in a yet existing example in the rename section.

I've added this note:

        Also note that the -d formatting applies to date/time tags used in -if conditions
        unless the print conversion is disabled by adding a # suffix to the tag name.


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

exiftewb

Quote
QuoteShould I've test against any no date tag, I'd never see this ?

I don't understand.
I meant: if I've tested (-if) against say $model (useless for me ATM), I would not need to add the # suffix as -d EXPR will only work on tags that are related to date/time.


Quote
QuoteMaybe it is worth to add some -if with -d example in a yet existing example in the rename section.

Honestly, I don't think that would help much.
These examples where of so huge help for me-newb when I was directed to exiftool (and man & site, BTW both very well written, full of remarks to newbies and useful real life examples), and exiftool being a so powerful piece of soft (I first thought I'd need to learn pearl when I read the man section for -if), that something likeexiftool "-filename<CreateDate" -d %Y%m%d-%H%M%S-%%f.%%e -if '$CreateDate# ge "2006:04:02"' dir
Will prefix rename files with creation date whose date in CreateDate tag is after 2006, april 1st, 23h59m59s
in the man's -if or -d sections or rename examples would have encourage me to try to understand the tag# thing.
BTW, after you gave me the tag# tip, I browsed the man for # trying to understand what is this for, but the "disable print conversion" explanation left me perplexed (Okay my $CreateDate won't print on paper, but not even on screen, and okay, if parents always babble, babies will never learn to speak, but although I feel at least an example of the usefulness of # suffix and/or the extent of -d that is able to spread across the borders of a string that is enclosed in a double wall of simple and double quotes are missing somewhere in the manual or site examples).

Whatever, thanks once more Phil for this what I guess a titanic work.

Phil Harvey

Quote from: exiftewb on July 28, 2017, 09:21:40 AM
I meant: if I've tested (-if) against say $model (useless for me ATM), I would not need to add the # suffix as -d EXPR will only work on tags that are related to date/time.

Correct.

Quote
QuoteMaybe it is worth to add some -if with -d example in a yet existing example in the rename section.

Honestly, I don't think that would help much.

Instead I added a note and edited my last post accordingly.

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

exiftewb

You better know where is the best place. While writing I though "maybe the double wall may be crossed by other things than -d so -if section could be the right place, but maybe other things than -if may require single+double quotes... ho chit!" and forgot it  ::)
For my general knowledge, print conversion is some pearl kind of shell expansion ?

Phil Harvey

Print conversion (PrintConv) is an ExifTool feature that is explained in a bit more detail here.

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

exiftewb

Oh my gode, hell beautiful 8) ... and simple   :)
And below is the tag names index that shows the madness of camera makers. Was this collection done by reverse engineering or do they publish their specs? Even simple picture viewers must turn bigger and bigger with al that stuff inside.

Have a good week-end Phil. Holidays maybe ?

Phil Harvey

Unfortunately the camera makers do not publish any information about their metadata formats.  Many people have helped with the decoding of this information.

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