ExifTool Forum

ExifTool => Newbies => Topic started by: mak on December 21, 2021, 11:58:03 PM

Title: Re: Set Date Taken from File Name
Post by: mak on December 21, 2021, 11:58:03 PM
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!
Title: Re: Re: Set Date Taken from File Name
Post by: StarGeek on December 22, 2021, 01:07:48 AM
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.
Title: Re: Re: Set Date Taken from File Name
Post by: mak on December 22, 2021, 08:29:58 AM
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.
Title: Re: Re: Set Date Taken from File Name
Post by: Phil Harvey on December 22, 2021, 09:10:01 AM
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
Title: Re: Re: Set Date Taken from File Name
Post by: mak on December 22, 2021, 09:57:40 AM
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.
Title: Re: Set Date Taken from File Name
Post by: StarGeek on December 22, 2021, 11:05:59 AM
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
Title: Re: Set Date Taken from File Name
Post by: Phil Harvey on December 22, 2021, 12:53:09 PM
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
Title: Re: Set Date Taken from File Name
Post by: mak on December 22, 2021, 09:09:11 PM
Exiftool version is 12.3.8.0

Filesystem is NTFS
Title: Re: Set Date Taken from File Name
Post by: Phil Harvey on December 23, 2021, 01:10:20 PM
OK, thanks.  Nothing unusual there.  I can't explain what you are seeing.

- Phil
Title: Re: Re: Set Date Taken from File Name
Post by: jwilleke on May 30, 2024, 07:30:37 AM
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!
Title: Re: Set Date Taken from File Name
Post by: StarGeek on May 30, 2024, 10:23:49 AM
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/
Title: Re: Re: Set Date Taken from File Name
Post by: sans_lingus on April 14, 2025, 01:56:47 PM
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!
Title: Re: Re: Set Date Taken from File Name
Post by: Phil Harvey on April 14, 2025, 02:53:59 PM
It sounds like you are using PowerShell maybe.  Be sure you are using cmd.exe and not PowerShell.

- Phil
Title: Re: Re: Set Date Taken from File Name
Post by: StarGeek on April 14, 2025, 03:50:34 PM
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.

Title: Re: Re: Set Date Taken from File Name
Post by: sans_lingus on April 14, 2025, 04:06:26 PM
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.