I wanted to build an awesome place for people to discuss module specific issues, but I don't have any more time for this, and there are much better places to discuss Perl-related issues. I'd recommend asking your question on Stack Overflow or on Perl Monks.
If you are looking for a Perl tutorial or Perl-related news, I hope these links will serve you well.
Posted on 2008-07-14 10:22:04-07 by justin
Help Using Conditional Logic Please

In the light of the following problem with Adobe Lightroom 1.4: http://www.adobeforums.com/webx?14@@.59b552d0/5, I would like to use Exiftool to correct some time related errors in my image library. However, I would prefer to do this before importing into Lightroom rather than have lightroom incorrectly write the EXIF date fields.

My library is structure in folders by year (YYYY), month (MM) and day (DD). I am also running multiple cameras. I would like to be able to configure a batch file to shift exif:alldates by an amount where the camera model is equal to some value and the dates are between a beginning and an end value.

For example; my first task is to shift all images taken with my Nikon D200 forward 1 hour between the dates of 30/03/2008 and the 10/06/2008 (the day I realised my DST was not set active on my camera! D'oh!)

For what it's worth I've tried to make a start using: exiftool -model * -if "$model=NIKON D200" but it does not seem to be reading files where the model = "Nikon D200" as listed in the: exiftool -model tag

Many thanks for any help! Justin..

Direct Responses: 8296 | Write a response
Posted on 2008-07-14 11:33:27-07 by exiftool in response to 8294
Re: Help Using Conditional Logic Please
Hi Justin,

What you have done will work, except the Perl string comparison operators are "eq", "lt", "le", "gt" and "ge". The "=", "lt;", "lt;=", "gt;" and "gt;=" are numerical comparison operators. So your -if statement should be:

- if "$model eq 'NIKON D200' and $createdate ge '2008:03:30' and $createdate le '2008:06:10'"

Note that in general you have to be careful using "eq" to test Model strings because sometimes you get trailing spaces in the model name. But in this case, the D200 doesn't have this problem. However, the way around this for other cameras is to use a regular expression to look for a substring:

-if "$model =~ /NIKON D200/"

- Phil
Direct Responses: 8298 | Write a response
Posted on 2008-07-14 13:14:23-07 by justin in response to 8296
Re: Help Using Conditional Logic Please
Hi Phil, thank you very much. This is really helpful! I'm much more inclined to trust my image library metadata to exiftool than Adobe's software at present! Justin..
Direct Responses: 8300 | Write a response
Posted on 2008-07-14 13:38:43-07 by exiftool in response to 8298
Re: Help Using Conditional Logic Please
Thanks for the vote of confidence. I noticed a couple of problems in my last post. First, I forgot the ampersand for the HTML character entities in this sentence:

What you have done will work, except the Perl string comparison operators are "eq", "lt", "le", "gt" and "ge". The "=", "<", "<=", ">" and ">=" are numerical comparison operators.

And second, I realized there is no use testing for equality since of course a date/time value can never equal '2008:03:30', so you are effectively stuck with "lt" and "gt" for your date tests. So to test 2008:03:30 to 2008:06:10 inclusive, the condition is:

-if "$createdate gt '2008:03:30' and $createdate lt '2008:06:11'"

This works because "2008:03:30 xx:xx:xx" is greater than "2008:03:30", but all date/time values on 2008:06:10 come before "2008:06:11" when compared as a string.

- Phil
Direct Responses: 8314 | Write a response
Posted on 2008-07-15 14:39:44-07 by beach9000 in response to 8300
Re: Help Using Conditional Logic Please
As a follow up, what's the safe way to test conditions?

From the above have I have the following line in a Windows prompt:

exiftool -if "$model =~ /NIKON D300/" DSC_2808.jpg

and it gives me this response:

1 files failed condition

But if I do a normal exiftool on the file, I can get this line:

Camera Model Name : NIKON D300

When I first saw the failed condition error I thought that it meant my expression was wrong, but since I'm having a hard time getting it to succeed, I'm beginning to think that I've misinterpret it. Have I?

Eddy.

Direct Responses: 8317 | Write a response
Posted on 2008-07-15 15:35:55-07 by exiftool in response to 8314
Re: Help Using Conditional Logic Please
No. That should work. I tried this exact command with a sample D300 file here, and it does work. Very odd. If you could try some other expressions maybe you can narrow down the source of the problem. - Phil
Direct Responses: 8320 | Write a response
Posted on 2008-07-15 17:00:17-07 by beach9000 in response to 8317
Re: Help Using Conditional Logic Please

Thanks for the prompt response but I think I may have figured it out. Reading the note, that when typing commands in the "cmd.exe" shell, you should use double quotes instead of single quotes as shown in some examples, from http://www.sno.phy.queensu.ca/~phil/exiftool/ I wrapped by original line double quotes. I switched to single quotes and I got the same output as if I have just exiftool'ed the file. I'm assuming that this is the succeed output.

So what happened? Well I'm on Windows Vista but I'm working in PowerShell where the rules are reversed from a normal cmd.exe shell.

Direct Responses: 8326 | Write a response
Posted on 2008-07-16 10:35:17-07 by exiftool in response to 8320
Re: Help Using Conditional Logic Please
Glad you figured this out. Yes. The quoting rules are shell-dependent. I've never used PowerShell, but it sounds like it has more Unix-like rules.

- Phil
Direct Responses: Write a response