ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: stefanjoa on May 22, 2020, 03:25:35 AM

Title: Setting Datetimeoriginal based on directory name
Post by: stefanjoa on May 22, 2020, 03:25:35 AM
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/
Title: Re: Setting Datetimeoriginal based on directory name
Post by: StarGeek on May 22, 2020, 03:32:54 AM
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}
Title: Re: Setting Datetimeoriginal based on directory name
Post by: stefanjoa on May 22, 2020, 03:58:30 AM
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/
Title: Re: Setting Datetimeoriginal based on directory name
Post by: Phil Harvey on May 22, 2020, 05:46:08 AM
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
Title: Re: Setting Datetimeoriginal based on directory name
Post by: stefanjoa on May 22, 2020, 06:18:37 AM
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?
Title: Re: Setting Datetimeoriginal based on directory name
Post by: StarGeek on May 22, 2020, 12:49:00 PM
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")}