Author Topic: Read datecreate from txt  (Read 120 times)

Trebol-a

  • Newbie
  • *
  • Posts: 4
Read datecreate from txt
« on: January 15, 2019, 06:37:15 AM »
Hi,
how I can write a tag date value from a txt file?
I have one txt for every jpg with datecreate in format: "Mon, 14 Jan 2019 00:00:00 +0100"

How i can to do something like? : exiftool "-datecreate<$(cat filedate.txt)" my_picture.jpg

or

rename with something like: exiftool "-filename=${filedate.txt}" -d "PICTURE_%Y%m%d.jpg " my_picture.jpg

Best regards

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14405
    • ExifTool Home Page
Re: Read datecreate from txt
« Reply #1 on: January 15, 2019, 07:30:38 AM »
First.  I don't know what you mean by datecreate.  For my examples I will assume you meant EXIF CreateDate.

If the date/time was formatted with the year first and using a numerical month, this would be simple:

exiftool "-createdate<=%d%f.txt" DIR

But it will be tricky to handle the format you used.  In theory, this should work:

exiftool "-createdate<=%d%f.txt" -d "%a, %d %b %Y %H:%M:%S %z" DIR

But this depends on external libraries that may or may not work on your system.  It didn't work for me on MacOS (it got the date OK, but not the time).

If this doesn't work, parsing the date manually is do-able, but it would be messy and require the creation of a user-defined tag.

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

Trebol-a

  • Newbie
  • *
  • Posts: 4
Re: Read datecreate from txt
« Reply #2 on: January 15, 2019, 10:32:01 AM »
Yes, a mistake, CreateDate is correct! :D

I have a lot of JPGs - TXT pairs, like
Code: [Select]
IMAG001.JPG
IMAG001.JPG.txt
IMAG002.JPG
IMAG002.JPG.txt
IMAG003.JPG
IMAG003.JPG.txt
...

The JPGs have not the tag CreateDate, this data is containing in the txt at format "Mon, 14 Jan 2019 00:00:00 +0100" (from date on  Linux SO).
I can to make on bash :
Code: [Select]
> cat IMAG0003.JPG.txt | date "+%Y/%m/%d 12:35:46" -d -
> 2019/01/15 12:35:46
I need read every txt, parse content and insert on tag CreateDate (or other) of my JPGs.

How could I do something like : exiftool -createdate<=$( cat IMAG0003.JPG.txt | date "+%Y/%m/%d 12:35:46" -d - ) IMAG003.JPG
or
Can Exiftool read the stdin on Linux system?

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14405
    • ExifTool Home Page
Re: Read datecreate from txt
« Reply #3 on: January 15, 2019, 10:46:16 AM »
I was wrong.  My command does work.  I thought it wasn't working because the time was getting set to 00:00:00, but that is what it should be.  (I used your example time)

The only problem with my command is that I assumed FILE.JPG would have text file FILE.txt, but it is FILE.JPG.txt.  So this command should work:

exiftool "-createdate<=%d%f.%e.txt" -d "%a, %d %b %Y %H:%M:%S %z" 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 ($).

Trebol-a

  • Newbie
  • *
  • Posts: 4
Re: Read datecreate from txt
« Reply #4 on: January 15, 2019, 11:48:47 AM »
Thank you very much, work perfectly.  ;D