Author Topic: Problem when using -d and -if arguments together  (Read 701 times)

badigast

  • Newbie
  • *
  • Posts: 2
Problem when using -d and -if arguments together
« 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.

Code: [Select]
#!/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:
Code: [Select]
exiftool "-TestName<DateTimeOriginal" -If '$datetimeoriginal gt "'$DATE1'"' -If '$datetimeoriginal lt "'$DATE2'"' ./*

It works with the -if argument removed, too:
Code: [Select]
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!


Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 16885
    • ExifTool Home Page
Re: Problem when using -d and -if arguments together
« Reply #1 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
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

badigast

  • Newbie
  • *
  • Posts: 2
Re: Problem when using -d and -if arguments together
« Reply #2 on: October 23, 2017, 02:19:22 PM »
That worked perfectly.

Thanks a lot!