Setting Datetimeoriginal based on directory name

Started by stefanjoa, May 22, 2020, 03:25:35 AM

Previous topic - Next topic

stefanjoa

Hi,

I want to set the datetimeoriginal based on the directory, if the datetimeoriginal is empty. I tried some things, but it does not work.
Do you have any idea?

An example for a directory is:
/volume1/photos/2001/01.01.2001/

I tried the following command:
exiftool "-datetimeoriginal<${directory;.*(\d{2}\.\d{2}\.\d{4}).*//} 00:00:00.000"  -if '(not $datetimeoriginal or ($datetimeoriginal eq "0000:00:00 00:00:00")) and ($filetype eq "JPEG")' /volume1/photos/2001/01.01.2001/

StarGeek

It's unclear whether your format is MM.DD.YYYY as in the U.S. or DD.MM.YYYY as used elsewhere.

Try this for the directory entry if the first, otherwise swap $1 and $2
${directory;m/(\d{2})\.(\d{2})\.(\d{4})/;$_=$3$1$2}
"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

stefanjoa

Thanks!

After executing your command the command line shows the following error:
-sh: -datetimeoriginal<${directory;m/(\d{2})\.(\d{2})\.(\d{4})/;$_=$3$2$1} 00:00:00.000: bad substitution

What am I doing wrong?

My new command looks like this:
exiftool "-datetimeoriginal<${directory;m/(\d{2})\.(\d{2})\.(\d{4})/;$_=$3$2$1} 00:00:00.000"  -if '(not $datetimeoriginal or ($datetimeoriginal eq "0000:00:00 00:00:00")) and ($filetype eq "JPEG")' /volume1/photo/2005/03\ -\ März\ 2005/25.03.2005/

Phil Harvey

Try this:

exiftool '-datetimeoriginal<${directory;m/(\d{2})\.(\d{2})\.(\d{4})/;$_="$3$2$1"} 00:00:00.000'  -if '(not $datetimeoriginal or ($datetimeoriginal eq "0000:00:00 00:00:00")) and ($filetype eq "JPEG")' /volume1/photos/2001/01.01.2001/

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

stefanjoa

That worked! Thank you!

Is it possible to use the date from the filename and the time from the fileCreatedDate instead of 00:00:00.000?

StarGeek

Quote from: stefanjoa on May 22, 2020, 03:58:30 AM
What am I doing wrong?

You didn't mention you were not on Windows ;) (just teasing)

Quote from: stefanjoa on May 22, 2020, 06:18:37 AMIs it possible to use the date from the filename and the time from the fileCreatedDate instead of 00:00:00.000?

Replace 00:00:00 with ${FileCreateDate;DateFmt("%H:%M:%S")}
"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