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 2007-04-20 16:32:09-07 by pdi
-if with DateTimeOriginal
I am using the exif:DateTimeOriginal tag to rename fotos. Occasionally there are fotos with DateTimeOriginal set to 0000:00:00 00:00:00. In this case I want to rename them using the FileModifyDate tag. Now, when I do

exiftool -if "$exif:DateTimeOriginal eq '0000:00:00 00:00:00'" -r -s -s -s -exif:DateTimeOriginal D +IR

exiftool correctly identifies the fotos. But when I use the same condition in

exiftool -if "$exif:DateTimeOriginal eq '0000:00:00 00:00:00'" -r "-FileName<FileModifyDate" -d "%% +-.1d_%Y%m%d_%H%M%S%%-2c.%%e" "-directory=%d" DIR

exiftool reports ALL fotos as having failed the condition. I work from dos cmd, on w2k, with win executable ver 6.74 or normal 6.79.

I wonder if I'm missing something. Any ideas? Many thanks in advance.
Direct Responses: 4942 | Write a response
Posted on 2007-04-20 16:45:34-07 by exiftool in response to 4941
Re: -if with DateTimeOriginal
The reason is that you've modified the value of DateTimeOriginal with the -d option, so it no longer looks like '0000:00:00 00:00:00', but now instead takes the form of a filename. If you want to do this, you will have to change your test to something like:

-if "$exif:DateTimeOriginal =~ /00000000_000000/" ...

I hope this makes sense (presuming of course you understand Perl regular expressions.. ;)

Also, you can set the filename and directory together with:

-d "%%d%%-.1d_%Y%m%d_%H%M%S%%-2c.%%e"

This saves having to assign -directory separately, but this is off the topic of your original question.

- Phil
Direct Responses: 4943 | Write a response
Posted on 2007-04-20 16:50:43-07 by exiftool in response to 4942
Re: -if with DateTimeOriginal
Wait. But settingn "-directory=%d" moves it to the current directory, which has no effect. So why set it at all?

- Phil
Direct Responses: 4944 | Write a response
Posted on 2007-04-20 18:02:21-07 by pdi in response to 4943
Re: -if with DateTimeOriginal
Phil,

Thank you very much, I wouldn't have spotted it :-) I'm not familiar with Perl, but I got the gist of the pattern matching you propose and it works.
I found a peculiar quirk though. When using the first command from my first post the DateTimeOriginal of those fotos is reported correctly as 0000:00:00 00:00:00. When I test with

exiftool -if "$exif:DateTimeOriginal =~ /00000000_000000/" -r -s -s -s -FileModifyDate -d "%Y%m%d_% +H%M%S" DIR

nothing comes up. It turns out that, for some reason, the formatting of 0000:00:00 00:00:00 results in 00000002_000000 instead of 00000000_000000. I cannot tell if it is due to the obviously poor EXIF data or my lack of understanding of exiftool.

By the way, thank you for your suggestion about -directory tag, but it got there due to the needs of the naming scheme and with your help (see thread 4243).

pdi
Direct Responses: 4945 | Write a response
Posted on 2007-04-20 18:31:38-07 by exiftool in response to 4944
Re: -if with DateTimeOriginal
Ah right. I didn't think of this problem.

Invalid date/times may give unpredictable results. If they are inside the range for strftime, they are usually handled reasonably (ie. a day of "0" is actually the last day of the month before, and a month of "0" is December of the year before). So if you set -DateTimeOriginal="2007:00:00 00:00:00", and then read it back again with -d %Y%m%d -datetimeoriginal, you will get "2006:11:30". Which may not be what you expected, but makes more sense date-wise.

But the year "0000" is obviously not being handled properly, since it is well out of range for strftime.

So this becomes a slightly trickier problem than I initially thought, particularly since the conversion of 0000:00:00 is likely to be system dependent (although on my Mac here it also gives 0000:00:02).

But at least on your system you can check for /00000002_000000/. It isn't pretty, but at least it gets you going.

"By the way, thank you for your suggestion about -directory tag, but it got there due to the needs of the naming scheme and with your help (see thread 4243)."

Ah, yes. That was tricky. I remember now -- the %-.1d may still contain directory separators (/). Right. So you do need the separate -directory=%d.

- Phil
Direct Responses: 4946 | Write a response
Posted on 2007-04-21 03:17:37-07 by pdi in response to 4945
Re: -if with DateTimeOriginal
Phil,

So if you set -DateTimeOriginal="2007:00:00 00:00:00", and then read it back again with -d %Y%m%d - +datetimeoriginal, you will get "2006:11:30".

I understand the reasoning with day 0 being the last day of the previous month and so on, but I would have expected "2007:00:00 00:00:00" to become "2006:12:31" instead of "2006:11:30". And, if the previous period rule works cumulatively from left to right, I'd have expected "2006:11:29", falling back one day as "00:00:00" would become "23:59:59". Nevertheless, I tested it with a foto and for some reason it cannot be formatted as %Y%m%d at all but remains in the original format.

But at least on your system you can check for /00000002_000000/. It isn't pretty, but at least it g +ets you going.

This is exactly what I ended up doing. I agree it's not pretty, but it works fine.

pdi
Direct Responses: 4947 | Write a response
Posted on 2007-04-21 11:43:19-07 by exiftool in response to 4946
Re: -if with DateTimeOriginal
I don't understand the 0000:00:00 case (maybe I'll think about this more when I get a chance), but the 2007:00:00 case should make sense (if done left-to-right as you mentioned):

2007:01:01 is Jan 1, 2007
2007:00:01 is Dec 1, 2006 (1 month before)
2007:00:00 is Nov 30, 2006 (1 day before, November has 30 days)

So 2007:00:00 becomes 2006:11:30

- Phil
Direct Responses: 4949 | Write a response
Posted on 2007-04-21 13:10:29-07 by pdi in response to 4947
Re: -if with DateTimeOriginal
Phil,

I know. It occurred to me, after the post, that I was making the hours:minutes:seconds behave in the same way, even though 00:00:00 is perfectly valid. It takes some getting used to this date dance :-)Thank you for the clarification.

pdi
Direct Responses: Write a response