Setting dates on MOV and MP4 files from directory name

Started by bobross, January 15, 2019, 11:38:05 AM

Previous topic - Next topic

bobross

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.

Phil Harvey

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

bobross

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?

Phil Harvey

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

bobross

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.

Phil Harvey

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

bobross

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



Phil Harvey

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

bobross

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.

Phil Harvey

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