Re: Set Date Taken from File Name

Started by mak, December 21, 2021, 11:58:03 PM

Previous topic - Next topic

mak

Hello,

I want to fix my whatsapp dates. they go like this "IMG-20151028-WA0000.jpg"
used this command here:
exiftool "-alldates<filename" /path/to/dir

the thing is it only changes the date taken for the pics. can this command be modified to also add the same date from file name so it changes it for  "date modified" and "date created" as well?

Thanks!

StarGeek

Quote from: mak on December 21, 2021, 11:58:03 PM
the thing is it only changes the date taken for the pics. can this command be modified to also add the same date from file name so it changes it for  "date modified" and "date created" as well?

The AllDates shortcut writes the EXIF:CreateDate and EXIF:ModifyDate as will as the EXIF:DateTimeOriginal] tag.  But I'm guessing what you really want to write is the file system timestamps.  To write to those, you would replace AllDates with FileCreateDate/FileModifyDate.  You can do all of them at once with
exiftool "-AllDates<Filename" "-FileCreateDate<Filename" "-FileModifyDate<Filename" /path/to/files/

But in the GUI, you would drop the "exiftool" and path part when setting up the exiftool direct box.
"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

mak

Thanks for quick reply.

I ran the command and it changed the  date taken and date modified but there was no affect on date created.
any ideas?
I am checking the changes in w7 windows explorer properties box under details.

Phil Harvey

What is the output of this command on one of the files, and what does Windows Explorer say?:

exiftool -time:all -G1 -a FILE

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

mak

Please check attachment.

first time running command was for original pic. second time was for updated pic with exiftool.
all dates get updated except for "file creation date/time". I am not sure if that is any problem.

StarGeek

That's very strange.  The FileAccessDate will get changed ever time the file is read, but the FileCreateDate should have been changed.

Here's how it works on my system
C:\>exiftool -time:all -g1 -a -s Y:\!temp\bbbb\img-20151204-wa0002.jpg
---- System ----
FileModifyDate                  : 2021:12:22 07:51:44-08:00
FileAccessDate                  : 2021:12:22 07:51:44-08:00
FileCreateDate                  : 2021:12:22 07:51:44-08:00

C:\>exiftool -P -overwrite_original "-AllDates<Filename" "-FileCreateDate<Filename" "-FileModifyDate<Filename"  Y:\!temp\bbbb\img-20151204-wa0002.jpg
    1 image files updated

C:\>exiftool -time:all -G1 -a -s Y:\!temp\bbbb\img-20151204-wa0002.jpg
[System]        FileModifyDate                  : 2015:12:04 00:02:00-08:00
[System]        FileAccessDate                  : 2021:12:22 07:56:19-08:00
[System]        FileCreateDate                  : 2015:12:04 00:02:00-08:00
[IFD0]          ModifyDate                      : 2015:12:04 00:02:00
[ExifIFD]       DateTimeOriginal                : 2015:12:04 00:02:00
[ExifIFD]       CreateDate                      : 2015:12:04 00:02:00
"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

That is odd.  Your FileCreateDate is behaving like StarGeek's FileAccessDate, and visa versa.

A couple of questions:

1. What version of ExifTool are you using?

2. What type of filesystem is the file on?

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

mak

Exiftool version is 12.3.8.0

Filesystem is NTFS

Phil Harvey

OK, thanks.  Nothing unusual there.  I can't explain what you are seeing.

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

jwilleke

I have several files in a folder where the filename starts with the date that I want the DateTimeOriginal to be.

Is there a method for the date from
2015-01-01-MtButler-540-5-1116.jpg
to become the DateTimeOriginal?

Thanks!

StarGeek

I'm assuming that none of the other numbers in the filename are the time?

The problem is that you need an actual time to complete the tag. Here's how you would write it using a time of midnight on that day
exiftool "-DateTimeOriginal<${Filename;m/(\d{4}-\d\d-\d\d)/;$_=$1;} 00:00:00" /path/to/files/
"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

sans_lingus

Quote from: StarGeek on May 30, 2024, 10:23:49 AMI'm assuming that none of the other numbers in the filename are the time?

The problem is that you need an actual time to complete the tag. Here's how you would write it using a time of midnight on that day
exiftool "-DateTimeOriginal<${Filename;m/(\d{4}-\d\d-\d\d)/;$_=$1;} 00:00:00" /path/to/files/


I am pulling my hair out; hoping someone can help with this. So I'm having a similar issue to the guy that the quoted post was responding to, but this script isn't working for me. My files are named in the format YYYY-MM-DD_randomCharacters87FGE79738BlahBlah-main.mp4 or .jpg. For instance, a real filename I have is 2016-07-27_16248D26-1427-4297-9FE4-783A527826A4-main.mp4. I need the date to be applied using AllDates and I found a post on Reddit with a script that goes through every file in a folder, so I tried using
exiftool -r -overwrite_original -progress "-AllDates<${Filename;m/(\d{4}-\d\d-\d\d)/;$_=$1;} 00:00:00" C:\Users\MyUserName\Desktop\Test
That threw me an error, saying that I needed a tick before the opening curly bracket for the variable. So then I ran
exiftool -r -overwrite_original -progress "-AllDates<$`{Filename;m/(\d{4}-\d\d-\d\d)/;$_=$1;} 00:00:00" C:\Users\MyUserName\Desktop\Test
That didn't throw any red errors, but it said there were syntax errors for 'Filename' in every file in the folder. It still changed some of them successfully, though.

I don't understand the syntax for this, whether it's CMD script stuff or ExifTool specific, so the ${Filename;m/(\d{4}-\d\d-\d\d)/;$_=$1;} is mostly just gibberish to me  :'( Is there a way to edit it for my filenames specifically? Or am I out of luck?

Thank you!

Phil Harvey

It sounds like you are using PowerShell maybe.  Be sure you are using cmd.exe and not PowerShell.

- 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

As Phil says, use CMD, not PowerShell. PowerShell has completely different quoting rules then every other command line and if you insist on using PS, you'll have to figure them out

Your command works correctly using CMD.

Example
C:\>exiftool -G1 -a -s -AllDates -File*Date Y:\!temp\x\y\2016-07-27_16248D26-1427-4297-9FE4-783A527826A4-main.mp4
[QuickTime]     CreateDate                      : 0000:00:00 00:00:00
[QuickTime]     ModifyDate                      : 0000:00:00 00:00:00
[System]        FileModifyDate                  : 2025:04:14 12:41:24-07:00
[System]        FileAccessDate                  : 2025:04:14 12:41:56-07:00
[System]        FileCreateDate                  : 2024:10:31 19:01:37-07:00

C:\>exiftool -r -overwrite_original -progress "-AllDates<${Filename;m/(\d{4}-\d\d-\d\d)/;$_=$1;} 00:00:00" Y:\!temp\x\y\2016-07-27_16248D26-1427-4297-9FE4-783A527826A4-main.mp4
======== Y:/!temp/x/y/2016-07-27_16248D26-1427-4297-9FE4-783A527826A4-main.mp4 [1/1]
    1 image files updated

C:\>exiftool -G1 -a -s -AllDates -File*Date Y:\!temp\x\y\2016-07-27_16248D26-1427-4297-9FE4-783A527826A4-main.mp4
[UserData]      DateTimeOriginal                : 2016:07:27 00:00:00-07:00
[XMP-exif]      DateTimeOriginal                : 2016:07:27 00:00:00
[QuickTime]     CreateDate                      : 2016:07:27 00:00:00
[XMP-xmp]       CreateDate                      : 2016:07:27 00:00:00
[QuickTime]     ModifyDate                      : 2016:07:27 00:00:00
[XMP-xmp]       ModifyDate                      : 2016:07:27 00:00:00
[System]        FileModifyDate                  : 2025:04:14 12:42:22-07:00
[System]        FileAccessDate                  : 2025:04:14 12:42:22-07:00
[System]        FileCreateDate                  : 2024:10:31 19:01:37-07:00

It's important to note that the AllDates shortcut doesn't mean all the time stamps in a file. It only includes the DateTimeOriginal, CreateDate, and ModifyDate tags. In the first listing, CreateDate and ModifyDate had no value, were set to zero. After the command, these tags in the Quicktime group where filled, as well as adding the DateTimeOriginal. Also, all three tags were filled in the XMP group.

The file system tags were not changed, as they aren't included in the AllDates shortcut. Those would have to be set separately.

"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

sans_lingus

Quote from: Phil Harvey on April 14, 2025, 02:53:59 PMIt sounds like you are using PowerShell maybe.  Be sure you are using cmd.exe and not PowerShell.

- Phil
Quote from: StarGeek on April 14, 2025, 03:50:34 PMAs Phil says, use CMD, not PowerShell. PowerShell has completely different quoting rules then every other command line and if you insist on using PS, you'll have to figure them out

Your command works correctly using CMD.

Yeah, I cannot believe I didn't realize this. Thank you guys so much. You're amazing.