test FileModifyDate

Started by luusac, September 06, 2017, 09:29:54 AM

Previous topic - Next topic

luusac

Hi,
Is there a way to output what the FileModifyDate will be set to without actually writing the FMDate?

e.g. exiftool -r '-FileModifyDate<CreateDate' . -ext jpg
e.g. file1.jpg 01/01/1997 -> file1.jpg 19/11/2016

I am looking for the kind of output that this would give:
exiftool -d %Y/%b/%%f_%d.%m.%Y_%H.%M.%S%%-c.%%e "-testname<DateTimeOriginal" . -ext jpg
(note testname not filename)

In the above the output will be original filename -> new year/month/newfilename.

I understand what the above commands do and that they are for different tasks, but as I want to set the FileModifyDate recursively I want to see what changes it will make before I commit them.  The output would therefore need to specify what the current FileModifyDate is, and what exiftool will change it to).  Is this possible without a shell script (linux user), if not, does anybody have a sample script?

Thanks

StarGeek

I'm not quite sure I understand, but maybe try:
exiftool -p "$Filename:  $FileModifyDate -> $CreateDate" -r -ext jpg .

Add -d to format the timestamp differently if you like.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

luusac

Apologies if my first post wasn't entirely clear.  I noiced that I had left the CreateDate in there instead of the DateTimeOriginal (as I was using that command last for movie files without a DateTimeOriginal).

Thanks, that was just the pointer that I needed - especially the -d.  My comparison was failing, I think, because

FileModificationTime = yyyy:mm:dd hh:mm:ss+02:00
DateTimeOriginal =      yyyy:mm:dd hh:mm:ss sub-seconds

-d and the format solved that.

So now I have:

exiftool -r -d "%Y:%m:%d %H:%M:%S" -p '$Filename:  $FileModifyDate -> $DateTimeOriginal' -if '($DateTimeOriginal and ($DateTimeOriginal ne "0000:00:00 00:00:00")) and ($DateTimeOriginal ne $FileModifyDate)' -ext jpg .

What I intend this to do is check that a DTO field exists, and if so, is not filled with 0's, and only then compare FileModifyDate with DateTimeOriginal.  If there is a mismatch between the last two, then print the FileModifyDate -> DateTimeOriginal.  So, if the logic is correct the same can be used to set the FileModifyDate from the DateTimeOriginal.

Is there a simpler/more elegant way to achieve this?

Is it possible to add to the command to commit the changes?  For example, in another context I use:
exiftool -d %Y/%b/%%f_%d.%m.%Y_%H.%M.%S%%-c.%%e "-testname<DateTimeOriginal" . -ext jpg
and if that gives the output I am looking for, I then modify it so:
exiftool -d %Y/%b/%%f_%d.%m.%Y_%H.%M.%S%%-c.%%e "-filename<DateTimeOriginal" . -ext jpg

I looked at the -execute option, but that looks as though it would be used to run a whole new command, rather than take the filename from the conditional match and then apply the '-FileModifyDate<DateTimeOriginal'.  Have I misunderstood -execute?
thank you

StarGeek

When copying DateTimeOriginal to FileModifyDate, you don't need to bother checking to see if it exists.  If it doesn't exist then the file will be skipped with a No writable tags warning. 

Do you actually have files with a 0000:00:00 00:00:00 time stamp?  Personally, I would just clear those out ahead of time because, IMO, it's a pretty useless bit of data.  It just seems odd. 

To commit the changes, just remove the -p '$Filename:  $FileModifyDate -> $DateTimeOriginal' section and replace it with '-FileModifyDate<DateTimeOriginal#'.  Here, I added the hashtag to the end of DateTimeOriginal so as to override the -d option.  In this case, it would have worked without it, but if the -d option was in a different order, there might have been problems.

For the actual write, you could also remove the DateTimeOriginal and FileModifyDate comparison, because if they are the same, there isn't going to be a change anyway. 

To wrap it all up, I would probably use this command to commit the changes:
exiftool -r -d "%Y:%m:%d %H:%M:%S" '-FileModifyDate<DateTimeOriginal#' -if '($DateTimeOriginal ne "0000:00:00 00:00:00")' -ext jpg .

Unless you go ahead and clear out the "0000:00:00 00:00:00" timestamps ahead of time.  In that case, all you would need is the basic:
exiftool -r '-FileModifyDate<DateTimeOriginal'  -ext jpg .

As for the -execute option, yes, it's used to run a new command without incurring the overhead of restarting exiftool again.  A conditional from before the -execute option would either have to be repeated or would have to be part of the -common_args option.  I wouldn't use it for your case as you wouldn't have time to inspect the output before it was committed.

You might also want to take a look at the -v option.  It might give you some insight into what exiftool is doing while writing and comparing.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

luusac

Quote from: StarGeek on September 06, 2017, 03:01:08 PM
When copying DateTimeOriginal to FileModifyDate, you don't need to bother checking to see if it exists.  If it doesn't exist then the file will be skipped with a No writable tags warning. 

Do you actually have files with a 0000:00:00 00:00:00 time stamp?  Personally, I would just clear those out ahead of time because, IMO, it's a pretty useless bit of data.  It just seems odd. 

Yes I do - the internal backup battery on my camera has failed, so anytime I remove the main battery for charging the date reverts to 1 Jan 1997.  When I have time I remember to reset it, but if I just grab the camera to take a quick photo I may forget to reset date/time afterwards and then I may end up taking a series.  I then end up with:

File Modification Date/Time     : 2007:01:01 00:00:00+00:00
...
Modify Date                           : 0000:00:00 00:00:00
Date/Time Original                 : 0000:00:00 00:00:00
Create Date                           : 0000:00:00 00:00:00

Later I have to try and remember/guess date/time and manually set it with exiftool.

So I can modify the search to pick up 0 date/times and 1/1/2007.  I have left out the File Access Date/Time and File Inode Change Date/Time above as are not relevant - but when I have this battery issue all images have the dates exactly as shown above.

Quote from: StarGeek on September 06, 2017, 03:01:08 PMAs for the -execute option, yes, it's used to run a new command without incurring the overhead of restarting exiftool again.  A conditional from before the -execute option would either have to be repeated or would have to be part of the -common_args option.  I wouldn't use it for your case as you wouldn't have time to inspect the output before it was committed.

You might also want to take a look at the -v option.  It might give you some insight into what exiftool is doing while writing and comparing.

Thanks for the help.

StarGeek

Quote from: luusac on September 14, 2017, 09:08:00 AM
Yes I do - the internal backup battery on my camera has failed, so anytime I remove the main battery for charging the date reverts to 1 Jan 1997.  When I have time I remember to reset it, but if I just grab the camera to take a quick photo I may forget to reset date/time afterwards and then I may end up taking a series.

Ouch, that's really annoying.

QuoteSo I can modify the search to pick up 0 date/times and 1/1/2007.I have left out the File Access Date/Time and File Inode Change Date/Time above as are not relevant - but when I have this battery issue all images have the dates exactly as shown above.

You can use
exiftool -if '($DateTimeOriginal eq "0000:00:00 00:00:00")'
to find all the files that have 0 dates. 
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).