Trouble setting file date from file name

Started by SergioUnoxx, January 30, 2022, 12:52:59 PM

Previous topic - Next topic

SergioUnoxx

Hi! I have a bunch of jpegs (named "photo_9@21-08-2017_12-12-58.jpg", "photo_10@21-08-2017_13-29-51.jpg", and so on) whose dates I want to change using their file names, and for that, I'm using the following command:

exiftool -d "photo_(\d+)@%d-%m-%Y_%H-%M-%S.jpg" "-createdate<filename" photo_9@21-08-2017_12-12-58.jpg

However, it yields an error:

Warning: Hour '58' out of range 0..24 in ExifIFD:CreateDate (PrintConvInv) - photo_9@21-08-2017_12-12-58.jpg
Warning: No writable tags set from photo_9@21-08-2017_12-12-58.jpg
    0 image files updated
    1 image files unchanged


It doesn't seem to recognize the 58 seconds as such, what could I be doing wrong? Thanks in advance!

StarGeek

#1
You can't use regex in the date format string.  You'll have to apply a regex to the Filename

exiftool "-CreateDate<${Filename;s/_\d+@(\d\d)-(\d\d)-(\d{4})/$3 $2 $1/}" /path/to/files/

You don't need to worry about non-numeric characters, those will be ignored (see FAQ #5).  You just have to make sure the number before the @ is removed and the date numbers are resorted.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

SergioUnoxx

I seem to be getting the same message:

C:\Users\Sergio\Desktop>exiftool "-CreateDate<${Filename;s/_\d+@(\\d\d)-(\d\d)-(\d{4})/$3 $2 $1/}" photo_9@21-08-2017_12-12-58.jpg
Warning: No writable tags set from photo_9@21-08-2017_12-12-58.jpg
    0 image files updated
    1 image files unchanged

C:\Users\Sergio\Desktop>exiftool -time:all -s photo_9@21-08-2017_12-12-58.jpg
FileModifyDate                  : 2022:01:30 18:35:41+01:00
FileAccessDate                  : 2022:01:30 20:59:43+01:00
FileCreateDate                  : 2022:01:30 18:32:11+01:00
CreateDate                      : 2022:01:30 18:32:11


If the CreateDate tag is created, what could be the problem?

StarGeek

Sorry, typo on my part.  There's an extra slash.  I'll fix the original post.

Working example
C:\>exiftool "-CreateDate<${Filename;s/_\d+@(\d\d)-(\d\d)-(\d{4})/$3 $2 $1/}" Y:\!temp\ccc\photo_9@21-08-2017_12-12-58.jpg
    1 image files updated

C:\>exiftool -G1 -a -s -CreateDate Y:\!temp\ccc\photo_9@21-08-2017_12-12-58.jpg
[ExifIFD]       CreateDate                      : 2017:08:21 12:12:58
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

SergioUnoxx

#4
This seems to work, yes, but only on some photos. On some others, the numbers before the @ symbol get recognized as the year (e.g.: "photo_6908@05-05-2021_21-00-49.jpg" receives a "05/05/6908, 20:21" date)

Is there any way to trim the file names so the "photo_6908@" part gets removed? (Having in mind that the numers range from "photo_1@" from "photo_7707@"

StarGeek

The command I gave does that.  It works correctly for that filename.
C:\Programs\My_Stuff>exiftool "-CreateDate<${Filename;s/_\d+@(\d\d)-(\d\d)-(\d{4})/$3 $2 $1/}" Y:\!temp\ccc\photo_6908@05-05-2021_21-00-49.jpg
    1 image files updated

C:\Programs\My_Stuff>exiftool -time:all --system:all -G1 -a -s Y:\!temp\ccc\photo_6908@05-05-2021_21-00-49.jpg
[ExifIFD]       CreateDate                      : 2021:05:05 21:00:49


You're still using the command that has the error in it, the one with two slashes
C:\Programs\My_Stuff>exiftool "-CreateDate<${Filename;s/_\d+@(\\d\d)-(\d\d)-(\d{4})/$3 $2 $1/}" Y:\!temp\ccc\photo_6908@05-05-2021_21-00-49.jpg
    1 image files updated

C:\Programs\My_Stuff>exiftool -time:all --system:all -G1 -a -s Y:\!temp\ccc\photo_6908@05-05-2021_21-00-49.jpg
[ExifIFD]       CreateDate                      : 6908:05:05 20:21:21

* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

SergioUnoxx