How to assign date and change file name in the same command?

Started by theprof, October 20, 2024, 11:57:49 AM

Previous topic - Next topic

theprof

Command is:
exiftool \
-overwrite_original \
-if '$MimeType=~/^video\//i' \
-if '(not defined $CreateDate or $CreateDate le "1970:12:31 23:59:59")' \
-api QuickTimeUTC \
'-AllDates<CreateDate' \
'-AllDates<DateTimeOriginal' \
'-AllDates<FileModifyDate' \
-d "%Y-%m-%d %H-%M-%S %%.2nc.%%e" '-FileName<AllDates' \
"$DIR"

Basically, I want to assign the "AllDates" and change the file name at the same time. How do I do that? It seems after changing the date, the file name goes to an old date (before it was set).

theprof

Can I run logic inside the "tag value assignment"?

For an example:
exiftool '-AllDates<{if CreateDate defined and greater than '1970-01-01' then CreateDate else if DateTimeOriginal defined and greater than '1970-01-01' then DateTimeOriginal else FileModifyDate}' "$DIR"


Basically I want to set "AllDates" tag by taking the value first from CreateDate, if that is not defined, then DateTimeOriginal and so on.

I tried -AllDates<FileModifyDate -AllDates<CreateDate -AllDates<DateTimeOriginal but then what happens is the date gets incorrectly set to "1903-01-01" etc because the CreateDate and DateTimeOriginal has a default/wrong date of 1903 for some of the files.

Phil Harvey

I would do it like this:

[tt]exiftool \
-overwrite_original \
-if '$MimeType=~/^video\//i' \
-api QuickTimeUTC \
'-AllDates<FileModifyDate#' \
'-AllDates<${DateTimeOriginal#;$_ = undef if $_ lt "1971"}' \
'-AllDates<${CreateDate#;$_ = undef if $_ lt "1971"}' \
-d "%Y-%m-%d %H-%M-%S %%.2nc.%%e" \
'-FileName<FileModifyDate' \
'-FileName<${DateTimeOriginal;$_ = undef if $_ lt "1971"}' \
'-FileName<${CreateDate;$_ = undef if $_ lt "1971"}' \
"$DIR"

Here I am copying to AllDates from the unformatted values (by adding "#" to the tag name) just as a precaution because a change to the -d formatting could otherwise break things.

Setting "$_" to "undef" in the advanced formatting expression will prevent the tag from being copied.

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

theprof

Quote from: Phil Harvey on October 20, 2024, 01:57:11 PMI would do it like this:

[tt]exiftool \
-overwrite_original \
-if '$MimeType=~/^video\//i' \
-api QuickTimeUTC \
'-AllDates<FileModifyDate#' \
'-AllDates<${DateTimeOriginal#;$_ = undef if $_ lt "1971"}' \
'-AllDates<${CreateDate#;$_ = undef if $_ lt "1971"}' \
-d "%Y-%m-%d %H-%M-%S %%.2nc.%%e" \
'-FileName<FileModifyDate' \
'-FileName<${DateTimeOriginal;$_ = undef if $_ lt "1971"}' \
'-FileName<${CreateDate;$_ = undef if $_ lt "1971"}' \
"$DIR"

Here I am copying to AllDates from the unformatted values (by adding "#" to the tag name) just as a precaution because a change to the -d formatting could otherwise break things.

Setting "$_" to "undef" in the advanced formatting expression will prevent the tag from being copied.

- Phil

Thanks, that simplified a lot of things.


I have one question. For both MOV, MP4, JPG, 3GP, PNG, HEIC files, should I write the "create date" to "AllDates" OR just the "CreateDate" tag?

Phil Harvey

I can't answer your question.  This depends on your personal preference and the tags that exist in these files beforehand.  One thing to consider is to change all of the date/time tags that already exist by writing -time:all instead of -alldates, but if you do this you must add -wm w so that you don't create new tags (only change existing ones).

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