Author Topic: How to change exif dates to match the file name?  (Read 16912 times)

quirino1977

  • Newbie
  • *
  • Posts: 5
Re: How to change exif dates to match the file name?
« Reply #15 on: February 04, 2017, 02:48:02 PM »
Hello.
This is what i need. But i didn't got it. I want to set exif dates with the date written it the filename.
I believe i will need a command like exiftool "-alldates<20$filename" -r DIR but my filenames are not date exactly.
My file pattern: 18F01-5-29(17-9).jpg where 18F is just picture number. Then i have YY-MM-DD(hh-mm). and month is not always 2-digit like in this example.
How can i tell exiftool the pattern? I have no idea how to ignore 3 firsts characters and how to treat the 1 or 2 digit month.

Thank's in advance.


Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14438
    • ExifTool Home Page
Re: How to change exif dates to match the file name?
« Reply #16 on: February 04, 2017, 09:24:01 PM »
Try this:

exiftool "-alldates<20${filename;s/^...//}" -r DIR

I think this should work if it is always 3 characters before the year.

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

quirino1977

  • Newbie
  • *
  • Posts: 5
Re: How to change exif dates to match the file name?
« Reply #17 on: February 05, 2017, 08:14:34 AM »
Try this:

exiftool "-alldates<20${filename;s/^...//}" -r DIR

I think this should work if it is always 3 characters before the year.

- Phil

You are right. It worked.  So i had run the same command with on more dot and one less dot as numbers got also 2 and 4 digits sometimes. I couldn't imagine the tool was so flexible to understand the different date mask (since my filenames do not use the left 0 when day and month have only one digit).

Also i had to change the quotes like your signature warns. (I use Linux). Already finishing to organize my pictures. This is the last big effort needed. The legacy cameras that makes a mess.

Thank you very much.

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14438
    • ExifTool Home Page
Re: How to change exif dates to match the file name?
« Reply #18 on: February 05, 2017, 09:42:04 AM »
I am sure we could find a pattern to match all cases if the prefix has a variable size.  Maybe something like this:

exiftool "-alldates<20${filename;s/^\d+.//}" -r DIR

which should handle a variable number of digits then remove one extra character.

BTW, FAQ 5 details the date/time formats the ExifTool accepts.

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

quirino1977

  • Newbie
  • *
  • Posts: 5
Re: How to change exif dates to match the file name?
« Reply #19 on: February 05, 2017, 07:08:11 PM »
Don't get bother about it. It's not a problem to run 3 commands. I will try this suggestion latter but i had already fixed all i needed.

Thank's a lot. I really appreciated your help.

quirino1977

  • Newbie
  • *
  • Posts: 5
Re: How to change exif dates to match the file name?
« Reply #20 on: February 11, 2017, 12:15:40 PM »
I am sure we could find a pattern to match all cases if the prefix has a variable size.  Maybe something like this:

exiftool "-alldates<20${filename;s/^\d+.//}" -r DIR

which should handle a variable number of digits then remove one extra character.

BTW, FAQ 5 details the date/time formats the ExifTool accepts.

- Phil

It worked for 3 and 4 digits. Not for 2. I took a look at the FAQ and others but find only one reference to s/ and looks like it's pearl, what i know nothing.

I couldn't imagine the tool was so flexible to understand the different date mask (since my filenames do not use the left 0 when day and month have only one digit).
Also i had to change the quotes like your signature warns. (I use Linux). Already finishing to organize my pictures. This is the last big effort needed. The legacy cameras that makes a mess.

Thank you very much.

Hayo Baan

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 938
  • Professional Photographer & Software Developer
    • Hayo Baan – Photography
Re: How to change exif dates to match the file name?
« Reply #21 on: February 11, 2017, 12:32:33 PM »
It worked for 3 and 4 digits. Not for 2. I took a look at the FAQ and others but find only one reference to s/ and looks like it's pearl, what i know nothing.

Its indeed a piece of perl that substitutes the first digits of the filename string. It matches 1 or more digits + one additional character so if you say it didn't work on files with 2 starting digits, that shouldn't be the case. What was the name of the file that didn't work? My guess is it simply followed a slightly different naming scheme.

Cheers,
Hayo
Hayo Baan – Photography
Web: www.hayobaan.nl

quirino1977

  • Newbie
  • *
  • Posts: 5
Re: How to change exif dates to match the file name?
« Reply #22 on: February 11, 2017, 01:38:24 PM »
Had not worked for 1F01-4-4(3-1).jpg.
Worked for 49F01-5-1(10-46).jpg and 114F01-8-18(17-15).jpg.

user@user-linux:~/Downloads/Image-ExifTool-10.41$ ls -l /home/user/Desktop/test/
-rw-rw-r-- 1 user user 45089 Fev 11 16:29 108F01-8-18(16-32).jpg
-rw-rw-r-- 1 user user 46153 Fev 11 14:58 2F01-4-4(3-2).jpg
-rw-rw-r-- 1 user user 47395 Fev 11 16:29 83F01-8-18(16-22).jpg

user@linux:~/Downloads/Image-ExifTool-10.41$ ./exiftool '-alldates<20${filename;s/^d+.//}' -r /home/user/Desktop/test/
Warning: No writable tags set from /home/user/Desktop/test/2F01-4-4(3-2).jpg
    1 directories scanned
    2 image files updated
    1 image files unchanged

user@user-linux:~/Downloads/Image-ExifTool-10.41$ ls -l /home/user/Desktop/test/
-rw-rw-r-- 1 user user 45089 Fev 11 16:29 108F01-8-18(16-32).jpg
-rw-rw-r-- 1 user user 45089 Fev 11 14:40 108F01-8-18(16-32).jpg_original
-rw-rw-r-- 1 user user 46153 Fev 11 14:58 2F01-4-4(3-2).jpg
-rw-rw-r-- 1 user user 47395 Fev 11 16:29 83F01-8-18(16-22).jpg
-rw-rw-r-- 1 user user 47395 Fev 11 14:38 83F01-8-18(16-22).jpg_original

user@user-linux:~/Downloads/Image-ExifTool-10.41$ ./exiftool '-alldates<20${filename;s/^..//}' -r /home/user/Desktop/test/
Warning: No writable tags set from /home/user/Desktop/test/108F01-8-18(16-32).jpg
Warning: No writable tags set from /home/user/Desktop/test/83F01-8-18(16-22).jpg
    1 directories scanned
    1 image files updated
    2 image files unchanged

user@user-linux:~/Downloads/Image-ExifTool-10.41$ ls -l /home/user/Desktop/test/
-rw-rw-r-- 1 user user 45089 Fev 11 16:29 108F01-8-18(16-32).jpg
-rw-rw-r-- 1 user user 45089 Fev 11 14:40 108F01-8-18(16-32).jpg_original
-rw-rw-r-- 1 user user 46153 Fev 11 16:32 2F01-4-4(3-2).jpg
-rw-rw-r-- 1 user user 46153 Fev 11 14:58 2F01-4-4(3-2).jpg_original
-rw-rw-r-- 1 user user 47395 Fev 11 16:29 83F01-8-18(16-22).jpg
-rw-rw-r-- 1 user user 47395 Fev 11 14:38 83F01-8-18(16-22).jpg_original


Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14438
    • ExifTool Home Page
Re: How to change exif dates to match the file name?
« Reply #23 on: February 11, 2017, 03:42:43 PM »
There aren't enough numbers for the time in some filenames.  Try this (add a couple of zeros for missing minutes and seconds):

exiftool '-alldates<20${filename;s/^\d+.//} 0 0' -r /home/user/Desktop/test/

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

jhoyos

  • Newbie
  • *
  • Posts: 1
Re: How to change exif dates to match the file name?
« Reply #24 on: March 24, 2017, 06:25:26 AM »
Hi,

I just discovered this software and I am really impressed.

This topic saved me a lot of time, so thanks in advanced for your help.

However, when applying:  "exiftool "-alldates<$filename" DIR", all the exif dates are changed but windows dates, as Date Created or Date Modified, are not changed.

Is there any way to change ALL dates, not only exif dates, but also windows dates? (created, modified, etc...)

Thanks in advanced.

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14438
    • ExifTool Home Page
Re: How to change exif dates to match the file name?
« Reply #25 on: March 24, 2017, 10:40:51 AM »
Try this:

exiftool "-alldates<filename" "-filecreatedate<filename" "-filemodifydate<filename" 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 ($).

BigBadWolf

  • Newbie
  • *
  • Posts: 7
Re: How to change exif dates to match the file name?
« Reply #26 on: April 30, 2017, 04:40:58 PM »
I have a slightly different issue.

I am restoring some of the old pictures from phones, and dates in exif are incorrect or not there at all. File name is the only source I can use, however, the file name is in following format 01-01-08_0022.jpg "mm-dd-yy_HHMM.jpg". Is there a way to set -alldates to use the file name in the following format? Any way I can convert filename to proper date format? Perhaps I can shift date elements in a filename around.

thank you very much.

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 2372
Re: How to change exif dates to match the file name?
« Reply #27 on: April 30, 2017, 08:07:08 PM »
Try this, assuming no pictures taken before the year 2000.  It also places the seconds at 00, since the seconds value isn't in the filename.
exiftool "-alldates<${filename;s/(\d\d)-(\d\d)-(\d\d)_(\d{4})/20$3-$2-$1_${4}00/}" FileOrDir

Example output:
Code: [Select]
C:\>exiftool -alldates "X:\!temp\01-01-08_0022.jpg"
Date/Time Original              : 2003:03:03 03:03:03

C:\>exiftool "-alldates<${filename;s/(\d\d)-(\d\d)-(\d\d)_(\d{4})/20$3-$2-$1_${4}00/}" "X:\!temp\01-01-08_0022.jpg"
    1 image files updated

C:\>exiftool -alldates "X:\!temp\01-01-08_0022.jpg"
Date/Time Original              : 2008:01:01 00:22:00
Create Date                     : 2008:01:01 00:22:00
Modify Date                     : 2008:01:01 00:22:00
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.

BigBadWolf

  • Newbie
  • *
  • Posts: 7
Re: How to change exif dates to match the file name?
« Reply #28 on: May 01, 2017, 03:28:10 PM »
Thanks a lot! That's exactly what I needed.

descotes

  • Jr. Member
  • **
  • Posts: 11
Re: How to change exif dates to match the file name?
« Reply #29 on: November 24, 2017, 04:42:51 PM »
Phil,

I seem to be having a problem with the file directory structure interfering with what I am trying to accomplish and wonder if there is a way around the problem.

I use a directory structure like this: Photos\YYYY\YYYY-MM\YYYY-MM-DD with photos being stored in the lowest folders only.

When I try to run the command: exiftools "-alldates<$directory 00:00:00" -r C:\Photos

I'm getting incorrect dates... it seems the date is being set from the full directory name instead of the immediate directory name for each file. Is there a way to force ExifTool to use the immediate directory name only? (I'm even getting illegal dates written with months >12). Do I need to run the command in each folder holding the files instead of in the folders in higher levels? (That would be a lot more work.)

Additionally, when I try running: exiftools "-FileModifyDate<$directory 00:00:00" -r C:\Photos

I get a warning about no writable tags but the list of tags indicates that FileModifyDate is writable. I have used an administrator level command window.

Clearly, I have some work to do before "earning my wings" for ExifTool...

Hi,

I'm new here.  This sounds like my situation but I don't understand coding.  Is there a step by step guide?  I have thousands and thousands of pictures that I want to change the dates for.  I downloaded your tool but I don't understand how to use it.  But this sounds like what I'd like to do.  Change the exif dates to the filename dates.  Can someone help?

Stacy