ExifTool Forum

ExifTool => Newbies => Topic started by: DrBarq on April 29, 2020, 04:54:27 PM

Title: Setting created date by file name
Post by: DrBarq on April 29, 2020, 04:54:27 PM
First off, thank you to Phil, the teams, and the community.  Wow, what a support network!  Very thankful to have found this tool.

I found this blog post and it has been very helpful https://arslan.io/2018/04/18/tips-tricks-to-batch-edit-exif-metadata-of-photos/
I've been searching the forum and I believe I have a regex problem.  I really want to understand how to handle these errors and would appreciate any help. 

Example1: IMG_0403.2014-11-07_004721.JPG
Example2: 2014-12-27_192124000_FB048_iOS.png

Example1: fails I believe due to the IMG prefix on the filename.  What command would I use to set the created date to the date information following the IMG prefix? 
exiftool "-AllDates<filename" *

returns
Warning: Invalid date/time (use YYYY:mm:dd HH:MM:SS[.ss][+/-HH:MM|Z]) in ExifIFD:DateTimeOriginal (PrintConvInv) - IMG_0403.2014-11-07_004721.JPG


Example2:  fails I believe due to .png.  Do I need to specify commands based on file types?  JPEG with similar file name/structure was updated without an issue.


Thank you for any help/advice!!

Title: Re: Setting created date by file name
Post by: StarGeek on April 29, 2020, 05:02:31 PM
Quote from: DrBarq on April 29, 2020, 04:54:27 PM
Example1: fails I believe due to the IMG prefix on the filename.

It isn't the image prefix, it's the numbers that are in front of the date.  Those can be removed with
exiftool "-AllDates<${Filename;s/^IMG_\d+//}" /path/to/files

See FAQ #5 (https://exiftool.org/faq.html#Q5) for details on how flexible exiftool is when dealing with dates.

QuoteExample2:  fails I believe due to .png. 

It shouldn't be a problem unless you're using a very old version of exiftool.
C:\Programs\My_Stuff>exiftool "-alldates<filename" "Y:\!temp\bb\2014-12-27_192124000_FB048_iOS.png"
    1 image files updated

C:\Programs\My_Stuff>exiftool -g1 -a -s -alldates "Y:\!temp\bb\2014-12-27_192124000_FB048_iOS.png"
---- PNG ----
CreateDate                      : 2014:12:27 19:21:24
ModifyDate                      : 2014:12:27 19:21:24
---- IFD0 ----
ModifyDate                      : 2014:12:27 19:21:24
---- ExifIFD ----
DateTimeOriginal                : 2014:12:27 19:21:24
CreateDate                      : 2014:12:27 19:21:24
Title: Re: Setting created date by file name
Post by: DrBarq on April 29, 2020, 06:46:03 PM
Thank you StarGeek!

That helped out a lot but I have a different issue now.  I was able to update/write the created date for the jpeg/png/mov

But I have an issue with the .mp4's; they look correct in finder/info with the correct created date but when in photos it references another date "January 5 181584"  this is applied to all mp4 and are now at the top of my Photos date. 


Any ideas? 
Title: Re: Setting created date by file name
Post by: DrBarq on April 29, 2020, 07:14:11 PM
I ran exiftool -time:all -a -G0:1 -s test and saw some fields weren't consistent per the screenshot below. (prefixed with a . or file name extension)  I imagine this is my problem?  is there an additional command I could run?



Title: Re: Setting created date by file name
Post by: StarGeek on April 29, 2020, 07:45:41 PM
Whoa, there's a lot of extra tags there.  You didn't happen to do something like this, did you?
exiftool '-time:all<$filename'

I'd suggest removing all the time tags and redoing it.  Replace the AllDates part with the correct command from above if needed.
exiftool -time:all= '-Alldates<Filename' /path/to/files/
Title: Re: Setting created date by file name
Post by: DrBarq on April 29, 2020, 08:03:48 PM
Quote from: StarGeek on April 29, 2020, 07:45:41 PM
Whoa, there's a lot of extra tags there.  You didn't happen to do something like this, did you?
exiftool '-time:all<$filename'


Is that asking because you are curious?  or "I hope he didn't do that"?  Just trying to learn either way



I just ran exiftool -time:all= '-AllDates<${Filename;s/^IMG_\d+//}' test
*test in this case is the name of the folder I am running the command on

It did something different.  now it says it was created in August 8, 174729.  thoughts?
Title: Re: Setting created date by file name
Post by: StarGeek on April 29, 2020, 09:07:13 PM
Ah, I finally remembered a previous problem with Photos.  See this thread (https://exiftool.org/forum/index.php?topic=10690.0).  The problem turned out to be the Quicktime:DateTimeOriginal tag (aka UserData:DateTimeOriginal.  So remove that with
exiftool -Quicktime:DateTimeOriginal= /path/to/files/

So for videos you're going to have to either set Quicktime:ModifyDate and Quicktime:CreateDate separately
exiftool  '-ModifyDate<${Filename;s/^IMG_\d+//}' '-ModifyDate<${CreateDate;s/^IMG_\d+//}' /path/to/files/

Or you could use the Alldates, if you have videos and images mixed in a directory, and then run the command above to remove the Quicktime:DateTimeOriginal tags.
Title: Re: Setting created date by file name
Post by: DrBarq on April 29, 2020, 10:30:46 PM
Thank you!! This is amazing.  You're the best. 
Title: Re: Setting created date by file name
Post by: Phil Harvey on April 30, 2020, 06:42:11 AM
I wish I knew what was happening here, but I wasn't able to reproduce this myself with MacOS 10.13.6 with Photos version 3.0 (https://exiftool.org/forum/index.php?topic=10690.msg56858#msg56858).

What version of MacOS and Photos are you running?

- Phil
Title: Re: Setting created date by file name
Post by: DrBarq on April 30, 2020, 10:12:16 AM
Hi Phil,

I am running macOS Catalina 10.15.4 and Photos version 5.0

The files came from Amazon Photos Mobile backup program and I had an issue with ~90 .mp4 files, no issues with the ~2k other .mov/.jpg/.png.   I just downloaded the original again to see if I could replicate and I could not.  It is very possible that I messed something up in the import.  Please let me know if you would like one of the files or have me try to replicate anything, happy to help in any way I can.   

Just curious, what photo management tool do you use?   
Title: Re: Setting created date by file name
Post by: Phil Harvey on April 30, 2020, 11:53:18 AM
If you could send me one of the problem files (with the crazy date), I'll try it here.  (my email is philharvey66 at gmail.com)

I use ExifTool and icat (https://exiftool.org/icat/) to manage my photo library.

- Phil
Title: Re: Setting created date by file name
Post by: StarGeek on April 30, 2020, 12:11:22 PM
Quote from: DrBarq on April 29, 2020, 10:30:46 PM
Thank you!! This is amazing.  You're the best.

It's all because Resultant took the time to figure it out.  I don't have access to a Mac so it wasn't something I could test.
Title: Re: Setting created date by file name
Post by: wywh on May 19, 2020, 03:02:14 AM
Quote from: DrBarq on April 29, 2020, 08:03:48 PM
now it says it was created in August 8, 174729.  thoughts?

I noticed that if "[Keys] CreationDate", "[UserData] DateTimeOriginal" and obviously also "[Quicktime] DateTimeOriginal" lack a timezone like +02:00, then Catalina's Photos.app 5.0 generates weird scrambled datetimes with the year displayed something like "177294" etc. So it is important to make sure a timezone is set there. For example, some exiftool commands like "-AllDates<filename" create "[UserData] DateTimeOriginal" without timezone by default.
Title: Re: Setting created date by file name
Post by: Martin Z on April 04, 2023, 03:21:16 PM
Quote from: StarGeek on April 29, 2020, 05:02:31 PMexiftool "-AllDates<${Filename;s/^IMG_\d+//}" /path/to/files

How "fuzzily" is EXIFtool able to match dates from int strings (in amongst other characters, seperators, etc)?, as in...

I assume I would need to separate out the files for each 'regex style' and process them in multiple batches, and create the correct regex that applies to each set of files specifically)... or is EXIFtool able to "fuzzy find" the date info for me as long as the file is in one of X / Y / Z formats, or contains a string of xxxxxx, etc?
Title: Re: Setting created date by file name
Post by: StarGeek on April 04, 2023, 07:32:01 PM
Quote from: Martin Z on April 04, 2023, 03:21:16 PMHow "fuzzily" is EXIFtool able to match dates from int strings (in amongst other characters, seperators, etc)?

It just needs the 14 numbers (maybe a few less?) in order from year->seconds, without regards to any intervening characters.

So if the numbers are out of order then they need to be reordered, usually by regex. If there are leading non-date/time numbers, then those also need to be removed.
Title: Re: Setting created date by file name
Post by: Martin Z on April 04, 2023, 08:19:09 PM
Quote from: StarGeek on April 04, 2023, 07:32:01 PMIt just needs the 14 numbers (maybe a few less?) in order from year->seconds, without regards to any intervening characters.

Hi @StarGeek, thanks for the quick reply! -- OK, no problem 👍🏼

In my case, the numbers aren't going to be in that format [as per some of the examples above, the date digits are most likely in the format like: "text-prefix_dd/mm/yyyy hhmmsss.ext"] however I am using a master Excel database* with various calculated columns and macros that will auto-generate and run EXIFtool commands.

As I have that platform (and I always struggle a bit with regex) I will probably just do any date extraction/manipulation in Excel and then send the date info (along with all the other metadata) through to EXIFtool as a formatted date. Thanks for clarifying though for reference / anyone else that will find it easier to use the '14 numbers' method.



* While people talking about / showing their impressive Excel 'databases' is a bit of a pet peeve of mine, as arguably Excel is not really the right tool for that. In this case because of the combination of a few factors, Excel does seem to be the best fit for this job -- don't judge me! 😇🙂