Copy Modified Date to Date Taken Only if Date Taken is Empty

Started by tron, October 08, 2018, 12:58:59 PM

Previous topic - Next topic

tron

Hi, I am brand new to ExifTool, so trying to figure out best way to tackle my issue.

I searched all the forum posts and found a few ways to do what I want, but hoping someone can fill in the gaps:

I have subfolders of photos (let's say 50+ subfolders) and inside those folders an average of about 50 photos.
Around 5-10 photos in random folders do not have "Date Taken" for various reasons.
But - they do have accurate Modified Date.
So I am thinking to copy Modified Date to Date Taken ONLY if Date Taken is empty, and to preserve modified date.

I have this so far but I am missing the "if empty" portion. Also will this do all subfolders under that root folder?

Thank you so much for any help!

exiftool "-datetimeoriginal<filemodifydate" -P DIR


StarGeek

Add the -wm (writemode) option and the -r (recurse) option

Recurse is simple, just add the -r and it will go into subdirectories.

Writemode needs an additional argument.  I'd say -wm cg is what you want to use.  It will not write to existing tags, just create new tags.

As with all things exiftool, another option would be to use the -if option.  In this case, -if "not $DateTimeOriginal" would write only if DateTimeOriginal didn't exist.
* 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).

tron

Thank you for the help!

OK so would this work below? I will test tonight, just double checking syntax.

The -if statement goes first? then the action? then write mode and -r for recurse?
Have not looked up what the -P means yet but not sure I need it.

Thanks again!


-if "not $DateTimeOriginal" "-datetimeoriginal<filemodifydate" -wm cg -r -P DIR


StarGeek

-if must be followed by the condition and -wm must be followed by the appropriate Mode flags, but otherwise, for the most part, the order doesn't matter (there is one other case where order would matter which I can discuss if you're interested).  If the -if condition fails, then the entire command is not processed.  You want to keep the -P (Preserve) option as it preserves the FileModifyDate, which you mentioned you wanted.

Test it out first, of course, to make sure it's doing what you want.
* 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).

tron

StarGeek thank you for the help, I updated a TON of photos over past few days.

First few runs were tricky but then I got the hang of it.

LOVE this Tool, big thanks for the developer and all those helping the newbs on the Forum!

loupraid

Hi all,

I am very new to ExifTool and find it challenging to use command line to get done what I need to do.

I am trying to 'clean up' my large photograph collection in the same way as mentioned in this thread. I have some photos missing the 'Date Taken' field. I wish to 'Copy Modified Date to Date Taken Only if Date Taken is Empty'.

I realise that tron who asked the question was able to correctly interpret what StarGeek has said to create the correct command line to achieve the objective. I am unable to do so.

Can you please provide me with the command line to do so, based on the above?

Thank you!

Phil Harvey

The command may be something like this:

exiftool "-datetimeoriginal<filemodifydate" -P -if "not $datetimeoriginal" -r DIR

This command will preserve "_original" files for each of the files that are changed.  Once you are sure the command did the right thing, you can remove the _originals with this command:

exiftool -delete_original -r DIR

Or if you already have backups and want to prevent the _original files from being preserved, add -overwrite_original to the first command.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

loupraid

Quote from: Phil Harvey on November 23, 2022, 09:14:58 AMThe command may be something like this:

exiftool "-datetimeoriginal<filemodifydate" -P -if "not $datetimeoriginal" -r DIR

This command will preserve "_original" files for each of the files that are changed.  Once you are sure the command did the right thing, you can remove the _originals with this command:

exiftool -delete_original -r DIR

Or if you already have backups and want to prevent the _original files from being preserved, add -overwrite_original to the first command.

- Phil

Thank you for the help, Phil, but I could not get this to work on my test folder of 28 JPEG files with missing date taken. From my limited understanding, is there supposed to be a -wm in there somewhere?

Phil Harvey

The -wm w was an alternate method.  You don't need this with the -if option I used.

You need to be more specific than just saying it didn't work.  What was the ExifTool output?

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

loupraid

Hi Phil,

Here is the output.



And here are the files.



Thank you

Phil Harvey

So all of the images already had a DateTimeOriginal.  According to StarGeek's post I thought this would fill the Windows "Date Taken" property.

Some investigation is required.  What does this command give on a file in question?:

exiftool -time:all -a -G1 -s FILE

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

loupraid


Phil Harvey

Ah.  That explains it.  The tags exist but are invalid dates.

I also think we should probably fix the other date/times too.  Try this somewhat longer command:

exiftool "-alldates<filemodifydate" -P -if "not $datetimeoriginal or $dateTimeOriginal !~ /^\d/" -r DIR

This will set the 3 date/time tags from the filesystem modification date if DateTimeOriginal doesn't exist or doesn't start with a digit.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

loupraid

Thank you! That works! Although it only seems to work on JPG files and not PNG or other types of files.

Is there any way to make it happen on other types of files too?

Phil Harvey

Looking at the post I referenced by StarGeek, it looks like you need to write CreationTime in PNG files.  Other types depends on what Windows will read from these files.  Check StarGeek's post, but for other formats you may have to do some testing.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).