Modify date based on parent folder

Started by cyian22002211, February 04, 2022, 05:55:10 PM

Previous topic - Next topic

cyian22002211

Hi there :)

All my files are arranged by folders in years eg: 'photos/2010'.

I would like to run a script which does the following.

1. If `$exif:datetimeoriginal` does NOT exist , add date based on the parent folder (1st Jan)
`exiftool -r -if 'not $exif:datetimeoriginal' -AllDates='[PARENT_NAME_FOLDER_FOR_YEAR]:01:01 00:00:00' -overwrite_original`
3. Set modify/create dates `exiftool -r "-FileModifyDate<EXIF:DateTimeOriginal" "-FileCreateDate<EXIF:DateTimeOriginal"`

Can you assist? Thanks

Phil Harvey

Do any folders above the parent have any 4 digit numbers in the name?  If not, then this will work:

exiftool -r -if 'not $exif:datetimeoriginal' '-AllDates<${directory}:01:01 00:00:00' -overwrite_original -ext jpg DIR

I have also added -ext jpg to avoid surprises in case there are other file types in the folder.  You can add more -ext options to process other types in the same command.

Then run your 2nd command to change all of the filesystem dates to DateTimeOriginal.

- 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 ($).

cyian22002211

Quote from: Phil Harvey on February 04, 2022, 09:50:04 PM
Do any folders above the parent have any 4 digit numbers in the name?  If not, then this will work:


Thanks. All folders have 4 digit numbers as their name (eg "2010") and no children folders inside of them. Is are you saying that won't work?

Phil Harvey

I'm saying that as long as the year is the only 4-digit number, this should work.

- 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 ($).