Renaming in bash script gives error but still works. Why?

Started by hvdwolf, August 14, 2021, 04:52:24 AM

Previous topic - Next topic

hvdwolf

Hi,

I normally use my own program to rename images, but in this case I wrote a quick script "prep_images.sh" to do it for me (datetimeoriginal due to wifi copy, and rename because that is what I want):
#!/bin/bash

Info () {
        printf "First give the name the images need to get\n\n"
        exit
}

########################################################################
## main part ##
# No output given?
if [ "$1" = "" ]
then
    Info;
fi
NAME="$1"

exiftool -m "-DateTimeOriginal>FileModifyDate" -d %Y%m%d '-FileName<${CreateDate}-'"${NAME}"'%-.2nc.%le'  '-fileorder datetimeoriginal#' *


So if I do something like "prep_images.sh TZ100", it will create files in a folder like:
20210802-TZ100-01.jpg
20210802-TZ100-02.jpg
etcetera

But for every file I do get the error:
Warning: Invalid date/time (use YYYY:mm:dd HH:MM:SS[.ss][+/-HH:MM|Z]) in File:FileModifyDate (PrintConvInv) - P1020477.JPG

It does work, so why?
See my jExifToolGUI cross-platform java application (Website, Releases, Changelog) for Phil's marvelous exiftool.

Phil Harvey

You're formatting the date/time with %Y%m%d and trying to copy that to FileModifyDate.  To do this you must avoid the formatting when copying this tag:

exiftool -m "-DateTimeOriginal#>FileModifyDate#" -d %Y%m%d '-FileName<${CreateDate}-'"${NAME}"'%-.2nc.%le'  '-fileorder datetimeoriginal#' *

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

hvdwolf

Thanks a lot. That indeed fixed it.

I would never have found that, also because I was too focused on the "'-FileName<${CreateDate} ...." part, as I thought that caused the error/warning, me trying to add a variable string between the normal exiftool variables.
See my jExifToolGUI cross-platform java application (Website, Releases, Changelog) for Phil's marvelous exiftool.

Phil Harvey

Note that the warning pointed you towards FileModifyDate:

Warning: Invalid date/time (use YYYY:mm:dd HH:MM:SS[.ss][+/-HH:MM|Z]) in File:FileModifyDate [...]

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