Set EXIF Date/Time from Enclosing Directory Name

Started by madra, May 25, 2016, 03:17:39 PM

Previous topic - Next topic

madra

I don't know if this is even possible, as I've only discovered ExifTool today and not had a chance to dive into the docs yet...

I've got several thousand photos in my archive, both digital and scanned from old negatives. They're all sorted into Directories by year taken and then further into sub-directories by precise date taken [where know]. Something like this:


2015
--2015-12-01
--2015-12-16
--2015-12-25 Xmas at Freds
--2015-12-28
--2015-12-31 NYE


[As you can see, the names some of the sub-directories also have indications as to the content]

For newish photos, this is fine, EXIF data coincides with my directory naming convention. However for all my pre-digital photos, there is either no EXIF data present, or it has been set [by Lightroom?] to the creation date of the image file, which will be whenever I scanned the original photo and bears no relation to the actual date the photo was taken.

What I want to do [if possible] is bulk add EXIF Date/Time to each image based on the name [or more precisely the first 10 characters of the name] of its enclosing directory. Does anyone reckon there a way to do this with ExifTool?

If the above isn't possible, I'd also welcome any suggestions that would allow me to use some  method to set the file creation/modification date based on the containing directory name, as I'd then be able to set the EXIF Date/Time from the file creation date. [I'm on OSX and/or Linux]

[BTW: The reason I want to achieve this is to avail of Flickr's free 1TB storage to backup my photo archive. At the moment, when I upload to Flickr, the photos come out in a complete jumble as, in lieu of EXIF data, Flickr is just arranging them by date uploaded.

StarGeek

Try this on a few test files first to see if it works for you:
exiftool '-datetimeoriginal<${directory;s/.*(\d{4})-(\d\d)-(\d\d).*/$1:$2:$3/} 00:00:00' FileOrDir

If that works, you can add a few options.  -r will recurse into subdirectories so you can give it the top level directory as an argument.  -overwrite_original will suppress the creation of backup files
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

photojoe


Hello, I too have the same setup and question!  I was not able to get the suggestion above working, any help is appreciated!  I am on Windows 10, exiftool version 10.20. I also tried another suggestion from a different thread with the same result.


S:\New Folder\a\2010-01-02>exiftool -v "-datetimeoriginal<${directory;s/.*(\d{4})-(\d\d)-(\d\d).*/$1:$2:$3/} 00:00:00" blah.jpg
======== blah.jpg
Setting new values from blah.jpg
Warning: No writable tags set from blah.jpg
Nothing changed in blah.jpg
    0 image files updated
    1 image files unchanged


S:\New Folder\a\2010-01-02>exiftool -v "-datetimeoriginal<${directory;s(/$)();s(.*/)()}" blah.jpg
======== blah.jpg
Setting new values from blah.jpg
Warning: No writable tags set from blah.jpg
Nothing changed in blah.jpg
    0 image files updated
    1 image files unchanged

S:\New Folder\a\2010-01-02>exiftool -s blah.jpg
ExifToolVersion                 : 10.20
FileName                        : blah.jpg
Directory                       : .
FileSize                        : 456 kB
FileModifyDate                  : 2016:06:19 13:01:50-04:00
FileAccessDate                  : 2016:06:19 13:17:00-04:00
FileCreateDate                  : 2016:06:19 13:01:50-04:00
<snip>
DateTimeOriginal                : 2015:04:02 14:47:51

Phil Harvey

The problem is that you didn't specify the directory name:

S:\New Folder\a\2010-01-02> exiftool -directory blah.jpg
Directory                       : .


Try this instead:

S:\New Folder\a\2010-01-02> cd ..
S:\New Folder\a> exiftool -v "-datetimeoriginal<${directory;s/.*(\d{4})-(\d\d)-(\d\d).*/$1:$2:$3/} 00:00:00" 2010-01-02


or, recursively for all subdirectories of "a":

S:\New Folder\a> exiftool -v -r "-datetimeoriginal<${directory;s/.*(\d{4})-(\d\d)-(\d\d).*/$1:$2:$3/} 00:00:00" .

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