Help me, I'm a noob please ;)

Started by marcusj, March 06, 2025, 09:35:13 AM

Previous topic - Next topic

marcusj

Hi! I'm trying to auto-edit the created date of all my video files in my Video Editing resource library. I am trying to match the date to any year listed in the title.

For example:
'(2s) John Cena Entrance 2023 IR.mp4' should apply the date 01/01/2023 (January 1st 2023) with the time 00:00.

However what is actually happening is that it is setting it to 01/04/2023 (April 1st 2023) with the time 01:00.

Here is my batch script:
@echo off
REM Set the ExifTool path
set EXIFTOOL_PATH=exiftool.exe

REM Loop through each MP4 file in the current directory
for %%F in (*.mp4) do (
    REM Extract year from filename using a regular expression
    for /f "tokens=2 delims=()" %%Y in ("%%F") do (
        REM Set year to be the extracted year
        set year=%%Y
        REM Apply the year to FileCreateDate
        "%EXIFTOOL_PATH%" -System:FileCreateDate="%%Y:01:01 00:00:00" "%%F"
        echo Updated: %%F with year %%Y
    )
)

REM Done, pause to show the result
echo All files have been updated!
pause

Also, with my alt files of a similar clip, I have named them with a 2 at the end. (For example '(2s) Kevin Owens Entrance 2022 IR 2').
However this is setting the date to 04/02/2022 (February 2nd 2022) at 01:01. Please could I get some assistance in forcing this to be the January 1st date at midnight too!

I am using the latest version of ExifTool.

Thank you kindly if you have the time to help me.

Phil Harvey

#1
I will delete this duplicate post.

See here to respond


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

StarGeek

Windows bat files aren't my strong suit, but doing some testing on the central loop, this is what the final exiftool command looks like
exiftool -System:FileCreateDate=" John Cena Entrance 2023 IR.mp4:01:01 00:00:00" "%F"

Obviously, all that text can't actually be part of a file date. But exiftool is flexible when writing date/time values.

From FAQ #5, How do I format date and time information for writing
QuoteHaving said this, ExifTool is very flexible about the actual format of input date/time values when writing, and will attempt to reformat any values into the standard format unless the -n option is used. Any separators may be used (or in fact, none at all).

You are parsing the filename to remove the leading "(2s)", which leaves "John Cena Entrance 2023 IR.mp4". Exiftool then takes all the numbers from that to start forming the time stamp. Notices that this includes the 4 from the extension, leading to a value of "2023:4:01 01:00:00".

An additional problem is that you are looping exiftool. Exiftool's biggest performance hit is the startup time, which means that this will take much longer than using exiftool's built-in batch ability (see Common Mistake #3, "Over-scripting")

Try this command.
exiftool -ext mp4 "-FileCreateDate<${Filename;$_=(m/(\d{4})/)?$1:undef;}:01:01 00:00:00" /path/to/files/

What this command does is take the Filename and tries to match four numbers. This number is captured and the value of the tag Filename is changed to that number (this does not change the actual name of the file). The value of that number plus the rest of the time stamp is then used to set the FileCreateDate. If the file does not have four numbers that can be used as a year, it will throw two warnings and skip that file
Warning: [minor] Advanced formatting expression returned undef for 'Filename'
Warning: No writable tags set from
These can be ignored

You would replace /path/to/files/ with the directory that you want to process. You can list multiple directories and individual files combined. For example, you could list this
"C:\Users\NAME\Pictures\My photo albums" D:\videos\MyVideo.mp4
and exiftool will process all the files in "My photo albums" as well as the single file "MyVideo.mp4"

The -ext (-extension) option is used to make sure only MP4 files are processed.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

StarGeek

Quote from: Phil Harvey on March 06, 2025, 10:19:23 AMI will delete this duplicate post.

See here to respond

Maybe delete the other post since I went to all this work :D
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

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

marcusj

Wow. Thank you very much StarGeek.

After your feedback, I was able to completely fix my code, and run it more efficiently. This means it also works with alt versions of my clips (with the '2' at the end).

I can't thank you enough. Much appreciated.

Here was the final code I ended up going with:
@echo off
REM Set the ExifTool path
set EXIFTOOL_PATH=ExifTool\exiftool.exe

REM Ensure we are in the correct directory with files
cd /d "%~dp0"

REM Run ExifTool on all MP4 files to update the FileCreateDate based on the year in the filename
"%EXIFTOOL_PATH%" -ext mp4 "-FileCreateDate<${Filename;$_=(m/(\d{4})/)?$1:undef;}:01:01 00:00:00" .

REM Done, pause to show the result
echo All files have been updated!
pause

Thanks again!

P.s. Sorry for the duplicate post, I wasn't sure if I posted it in the wrong section. My mistake!