ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: cyian22002211 on February 04, 2022, 05:55:10 PM

Title: Modify date based on parent folder
Post by: cyian22002211 on February 04, 2022, 05:55:10 PM
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
Title: Re: Modify date based on parent folder
Post by: 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:

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
Title: Re: Modify date based on parent folder
Post by: cyian22002211 on February 05, 2022, 09:51:49 PM
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?
Title: Re: Modify date based on parent folder
Post by: Phil Harvey on February 05, 2022, 09:54:07 PM
I'm saying that as long as the year is the only 4-digit number, this should work.

- Phil