ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: bobross on January 15, 2019, 11:38:05 AM

Title: Setting dates on MOV and MP4 files from directory name
Post by: bobross on January 15, 2019, 11:38:05 AM
I have an issue where I lost the original EXIF dates on years of MOV and MP4 files. I would like to be able to repopulate those values using dates from directory names. My photos and videos are stored as such.

~/[Year]/[Year_Month_Day]/*.MOV

(ex. ~/2014/2014_12_26/IMG_2080.MOV)

It's similar to this thread but I am not sure how to modify for my particular situation: https://exiftool.org/forum/index.php?topic=3807.0

The field Windows 10 version 1809 seems to honor for sorting is called "Origin / Media created." This is the value I need to add/overwrite. Thank you so, so much for any assistance.
Title: Re: Setting dates on MOV and MP4 files from directory name
Post by: Phil Harvey on January 15, 2019, 11:42:22 AM
I don't know if ExifTool will write the information you need, but the command could look something like this:

exiftool "-createdate<${directory;$_ = /(\d{4}_\d{2}_\d{2})/ ? qq($1 00:00:00) : undef" -ext mov -ext mp4 -api quicktimeutc DIR

- Phil
Title: Re: Setting dates on MOV and MP4 files from directory name
Post by: bobross on January 15, 2019, 11:46:17 AM
Amazing response time. I will try this tonight. What directory layer should I be in when the command is executed? Year or the individual day?
Title: Re: Setting dates on MOV and MP4 files from directory name
Post by: Phil Harvey on January 15, 2019, 11:48:41 AM
You can be at any directory level when you run this command, provided the date appears somewhere in or below the directory name you specify.  (ie. the only thing that won't work is changing to the day directory and specifying "." for DIR)

- Phil
Title: Re: Setting dates on MOV and MP4 files from directory name
Post by: bobross on January 15, 2019, 11:52:49 AM
I ran a test at the year level and this is the message I received. Thank you again.

C:\*\Pictures\ExifTest\2014>exiftool "-createdate<${directory;$_ = /(\d{4}_\d{2}_\d{2})/ ? qq($1 00:00:00) : undef" -ext mov -ext mp4 -api quicktimeutc DIR
Error: File not found - DIR
You were meant to enter any valid directory name, not "DIR" literally.
Title: Re: Setting dates on MOV and MP4 files from directory name
Post by: Phil Harvey on January 15, 2019, 11:54:13 AM
At the year level, replace "DIR" in the command with "." and add -r to the command (sorry, I forgot that) .  "." represents the current directory.

- Phil
Title: Re: Setting dates on MOV and MP4 files from directory name
Post by: bobross on January 15, 2019, 12:17:17 PM
Getting closer. I can update CreateDate with a basic script, however, when I run the batch script it says "No writable tags set." See output below.

Basic:
C:\*\Pictures\ExifTest\2014\2014_12_27>exiftool -CreateDate="2014:12:27 00:00:00" IMG_1366.MOV
    1 image files updated

Batch:
C:\*\Pictures\ExifTest\2014>exiftool "-CreateDate<${directory;$_ = /(\d{4}_\d{2}_\d{2})/ ? qq($1 00:00:00) : undef" -ext mov -ext mp4 -api quicktimeutc . -r
Warning: Search pattern not terminated for 'directory' - ./2014_12_27/IMG_1366.MOV
Warning: No writable tags set from ./2014_12_27/IMG_1366.MOV
Warning: Search pattern not terminated for 'directory' - ./2014_12_27/IMG_2080.MOV
Warning: No writable tags set from ./2014_12_27/IMG_2080.MOV
Warning: Search pattern not terminated for 'directory' - ./2014_12_29/IMG_1366.MOV
Warning: No writable tags set from ./2014_12_29/IMG_1366.MOV
    3 directories scanned
    0 image files updated
    3 image files unchanged


Title: Re: Setting dates on MOV and MP4 files from directory name
Post by: Phil Harvey on January 15, 2019, 12:24:12 PM
Sorry, I forgot the closing "}".  Try this:

exiftool "-CreateDate<${directory;$_ = /(\d{4}_\d{2}_\d{2})/ ? qq($1 00:00:00) : undef}" -ext mov -ext mp4 -api quicktimeutc -r .

- Phil
Title: Re: Setting dates on MOV and MP4 files from directory name
Post by: bobross on January 17, 2019, 12:58:42 PM
Following up on this post. I used this code on one year of MOV files and it worked. 100+ files got a Create Date that Windows 10 honors. Many years to go, but this process appears to work.

I cannot thank you enough for your tool and your help! Made a small donation to show my appreciation.
Title: Re: Setting dates on MOV and MP4 files from directory name
Post by: Phil Harvey on January 17, 2019, 01:07:03 PM
Thank you!