Author Topic: Set Date Taken from File Name  (Read 24664 times)

mbrijun

  • Newbie
  • *
  • Posts: 4
Re: Set Date Taken from File Name
« Reply #15 on: July 11, 2020, 02:47:53 AM »
Hi, this is a very useful functionality I have been looking for. One additional question - can exiftool detect if "AllDates" metadata is already present and skip that file without modifying it? Thank you.

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 5241
Re: Set Date Taken from File Name
« Reply #16 on: July 11, 2020, 03:11:50 AM »
I wouldn't know how to do it in the GUI (which is no longer supported) but on the command line you can add the -wm (writemode) option, specifically -wm cg which will create new tags and groups as necessary but will not write to existing tags.

But one thing to realize is that AllDates is a Shortcut tag and if one or two of the tags that are part of the shortcut don't exist, then it would write to those while leaving the others alone.  This could show up as discrepancies between time stamps.
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.

mbrijun

  • Newbie
  • *
  • Posts: 4
Re: Set Date Taken from File Name
« Reply #17 on: July 11, 2020, 05:37:21 AM »
on the command line you can add the -wm (writemode) option, specifically -wm cg which will create new tags and groups as necessary but will not write to existing tags.

this is exactly what I was looking for, thank you!

greglec

  • Newbie
  • *
  • Posts: 1
Re: Set Date Taken from File Name
« Reply #18 on: February 13, 2021, 10:21:59 AM »
Hi all, first of all many thanks for the really useful app! Saved me from having thousands of photos badly dated.

I have been updating the dates from the file name very well for many but, on some photos, I am struggling with the filename parsing.

They are named as such: 'Photo on 02-01-2016 at 11.55 #3.jpg' or  'Photo on 02-01-2016 at 11.57.jpg'

I am trying the following command : 'exiftool -d "Photo on %d-%m-%Y at %H.%M" "-alldates<filename" DIR'

But I am getting the following errors :
Warning: garbage at end of string in strptime: .jpg in ExifIFD:DateTimeOriginal (PrintConvInv) - Photo_on/Photo on 17-11-2015 at 21.13.jpg
Warning: No writable tags set from Photo_on/Photo on 17-11-2015 at 21.13.jpg

I am assuming that I need to ignore the characters in the file name after the minutes with input such as '${Filename;s/\.[^.]*$//}' but I am a bit lost on how to use it.

Any help?

Many thanks in advance.

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 18253
    • ExifTool Home Page
Re: Set Date Taken from File Name
« Reply #19 on: February 13, 2021, 11:50:56 AM »
strptime is very picky about the syntax, but I think this should work:

exiftool -d "Photo on %d-%m-%Y at %H.%M.jpg" "-alldates<filename" DIR

If that doesn't work, I would resort to using an advanced formatting expression, something like this:

exiftool "-alldates<${filename;s/.*(\d{2})-(\d{2})-(\d{4}) at (\d{2})\.(\d{2}).*/$3:$2:$1 $4:$5:00/ or $_ = undef}" DIR

- PHil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Jeneeben

  • Newbie
  • *
  • Posts: 2
Re: Set Date Taken from File Name
« Reply #20 on: April 14, 2021, 02:56:53 AM »
Hello,

I need to change the creation date of some scans based on the file name.
The syntax of the filename is: YYYY_MM_XXX and YYYY_MM

I tried to adjust the provided command: exiftool '-datetimeoriginal<${filename;$_=substr($_,0,7)} 00:00:00'

But I am getting "No writable tags set from ..." warning message.

How can I change the command to be able to get the Date from my file name?

Thanks in advance,
Jeneeben

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 5241
Re: Set Date Taken from File Name
« Reply #21 on: April 14, 2021, 10:53:45 AM »
A timestamp requires 14 numbers and if you give only the year and month, thats only 6 plus 6 more for the time portion.  You need to add a day to the command
Try
'-datetimeoriginal<${filename;$_=substr($_,0,7)} 01 00:00:00'
« Last Edit: April 14, 2021, 12:31:02 PM by StarGeek »
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.

Jeneeben

  • Newbie
  • *
  • Posts: 2
Re: Set Date Taken from File Name
« Reply #22 on: April 14, 2021, 12:22:10 PM »
Perfect, it is working :)

Thanks!