set CreateDate — if not defined

Started by c6y, March 26, 2017, 12:13:42 AM

Previous topic - Next topic

c6y

I'm trying to set CreateDate to the current date — but keep the original CreateDate, if already defined.

It's not working though, as the current date is always written, even if the file had a CreateDate already.

DATE=`date +%Y:%m:%d\ %H:%M:%S%z`
exiftool \
  -r \
  -all= \
  -CreateDate-= -CreateDate="$DATE" \
  -overwrite_original \
  .


Thanks!

Hayo Baan

Try this: DATE=`date +%Y:%m:%d\ %H:%M:%S%z`
exiftool \
  -r \
  -all= \
  -CreateDate="$DATE" \
  "-CreateDate<CreateDate" \
  -overwrite_original \
  .


This will keep the original CreateDate if there was one and still remove all other metadata.
Hayo Baan – Photography
Web: www.hayobaan.nl

Phil Harvey

Unfortunately the "-=" is a shift operator for date/time tags, so you can't use it for a conditional replacement.  Instead, Hayo's suggestion is good, but you can simplify your script to just this:

exiftool -r -all= -createdate=now "-createdate<createdate" -overwrite_original .

(ExifTool understands the word "now" as a date/time value)

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

c6y

Thanks Phil & Hayo. This works well!

Unfortunately it stops working when I add this line: -TagsFromFile @ -Software \. The result will always be that now is written to CreateDate. Why?

exiftool \
  -r \
  -TagsFromFile @ -Software \
  -all= \
  -createdate=now "-createdate<createdate" \
  -overwrite_original \
  .



c6y

#4
instead, this is what preserves the Software tag (if available) — and writes the CreateDate correctly:

exiftool \
  -r \
  -all= \
  -createdate=now "-createdate<createdate" \
  "-software<software" \
  -overwrite_original \
  .


this is strange though: if the software command is written before the createdate command, it will again only use now for the createdate (and ignore copying the existing value)

Thanks again!

Phil Harvey

Order matters.  Anything assigned before -all= won't get written (because -all= deletes everything).  See FAQ 22 for an explanation.

But I think you may be confused about what happens if the software argument comes before the createdate one.  These two arguments are independent, so order shouldn't matter (unlike with -all=, which affects all tags).

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