ExifTool Forum

ExifTool => Newbies => Topic started by: badigast on October 22, 2017, 04:26:32 PM

Title: Problem when using -d and -if arguments together
Post by: badigast on October 22, 2017, 04:26:32 PM
Hello everybody

I'm trying to write a bash script that renames files that were taken within a specific date range.

#!/bin/bash

DATE1="2001:01:01"
DATE2="2003:12:31"
EVENTID="abc"

exiftool "-TestName<DateTimeOriginal" -d "${EVENTID}_%Y-%m-%d_%H-%M-%S%%-c.%%le" -If '$datetimeoriginal gt "'$DATE1'"' -If '$datetimeoriginal lt "'$DATE2'"' ./*


->  1 files failed condition

When I remove the -d argument the script works fine though:

exiftool "-TestName<DateTimeOriginal" -If '$datetimeoriginal gt "'$DATE1'"' -If '$datetimeoriginal lt "'$DATE2'"' ./*


It works with the -if argument removed, too:
exiftool "-TestName<DateTimeOriginal" -d "${EVENTID}_%Y-%m-%d_%H-%M-%S%%-c.%%le" ./*


When I use the -d in combination mit -if I always get the message that the condition failed.


Any help is much appreciated.

Thanks!

Title: Re: Problem when using -d and -if arguments together
Post by: Phil Harvey on October 22, 2017, 09:08:38 PM
Adding the EVENTID to the start of your date/time values is messing up your comparison.

Use "$datetimeoriginal#" (ie. add the "#") to compare the unformatted date/time value in your -if condition.

- Phil
Title: Re: Problem when using -d and -if arguments together
Post by: badigast on October 23, 2017, 02:19:22 PM
That worked perfectly.

Thanks a lot!