ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: tutone on November 07, 2014, 12:58:01 PM

Title: Use folder name for year in datetimeoriginal
Post by: tutone on November 07, 2014, 12:58:01 PM
I have scanned pictures in different folders by year.  The pictures do not have "datetimeoriginal"; I want to use the folder name (which is the year) to set the year in datetimeoriginal.  For the month and day, I will just use 01/01 -- because the pictures are old and I only know the year.

I came across this post, which almost got me where I need to be:  https://exiftool.org/forum/index.php/topic,5172.msg24929.html#msg24929

I used this code:

exiftool "-datetimeoriginal<${directory;/(\d{4})/ ? $_=qq($1:01:01 00:00:00) : undef}" -overwrite_original

However, it seems to be trimming the directory too much so I only getting the upper level, which is the decade.

Pictures are stored as Pics/1950s/1951/

When I run the script, it sets the year as 1950 -- not 1951.  I am stumped.
Title: Re: Use folder name for year in datetimeoriginal
Post by: Phil Harvey on November 07, 2014, 01:10:14 PM
Close.

If you use /.*(\d{4})/ instead of /(\d{4})/, you should get the last 4-digit number in the directory name instead of the first.  (".*" causes it to skip as much as possible before matching the rest of the expression.)

- Phil