Author Topic: Use date in file name to write as "create date" of file  (Read 93 times)

MrT

  • Newbie
  • *
  • Posts: 2
Use date in file name to write as "create date" of file
« on: January 13, 2019, 05:09:18 PM »
Hi there,
As a complete beginner even lacking the most basic programming skills (I am sorry), I was hoping somebody could help me what command to use to copy a part of the file names of my pictures (which contain the correct date of creation) and save it as the "create date" of those pictures.

To be a little more precise:
My files cary a name like: IMG-20180328-WA0025.jpg (with March 28th being the correct creation date) but unfortunately, the files do not seem to have a creation date stored with it (running the exiftool command only shows me a "File Modification Date/Time, "File Access Date/Time", and "File Inode Change Date/Time".)
So is there any way I can extract the date from the file names and save it as the "creation date"? Of course I would not have the exact time, but that is not important to me, only the date is.

I would be incredibly grateful if somebody could help me out with command that does the trick!
Kind regards from Germany,
AT

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 13989
    • ExifTool Home Page
Re: Use date in file name to write as "create date" of file
« Reply #1 on: January 13, 2019, 05:15:00 PM »
Too bad the files don't have a time too, or the command would just be:

exiftool "-createdate<filename" DIR

(assuming you want to write the EXIF CreateDate information, but I am not exactly clear on what you mean by "creation date".  If you mean the filesystem creation date, then you can change createdate to filecreatedate and this should work on Windows or Mac)

But since your filenames don't have a time, it gets more complicated to remove the other numbers from the name and add in a time of 00:00:00.

exiftool "-createdate<${filename;$_=/(\d+)/ ? $1 : undef} 00:00:00" 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 ($).

MrT

  • Newbie
  • *
  • Posts: 2
Re: Use date in file name to write as "create date" of file
« Reply #2 on: January 16, 2019, 09:15:53 AM »
Wow... that is amazing, it worked like a charm, thank you sooo much!
I have to admit though that I was hoping to be able to decipher the command for the format below (so I could modify it for another file name format that I have) but I as a recreational computer user, I guess I don´t stand a chance... :(

Allow me therefore another question: what would this command look like if I would try to use it on a different format of files I ended up with, looking like:
2018.11.25 11/25/05.avi  ?

Also, what format does a file have to have for the command exiftool "-createdate<filename" DIR to work.
(Testing it on the file format: 2016-08-29_00.00.00.jpg didn´t work for me: it somehow made the application stop working)

And again, thank you very much for all your work, it is really impressive!
AT


Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 13989
    • ExifTool Home Page
Re: Use date in file name to write as "create date" of file
« Reply #3 on: January 16, 2019, 09:37:06 AM »
In my command, \d+ matches any number of digits.

So to match something like "2018.11.25", use \d+\.\d+\.\d+ instead of \d+ (the "." is a special character in regular expressions, so it needs to be escaped with a "\").  Replace \. with - to match dashes instead.  Or, to match any of these, and be sure we are getting the correct number of digits for each:

\d{4}[-.]?\d{2}[-.]?\d{2}

You can read about regular expressions if you want to learn more.

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