Posts Tagged ‘ExifTool’

Changing created/modify date of DNG files

August 16th, 2015 No comments

A “problem” I noticed when converting my RAW files to DNG is that the file creation date of the DNG files is the date the conversion was done. I would prefer if the creation date was the same date as when the photos were taken. As it turns out, you can easily change the creation date of a file by simply executing the following terminal command (Mac/Linux):

$ touch -t [YYMMDDHHMM] [filename]

This is fine except how do you know when a photo was taken? You could go to Lightroom (or some other application) to check but I prefer a command line interface. One excellent tool for this is ExifTool. This tool is so awesome that it’s even used by various commercial applications. In fact, I didn’t have to install this tool because it’s already bundled with Affinity Photo.

Once you have ExifTool, you can check the date the photo was taken by executing:

$ exiftool -createdate [filename]

Okay, now we can check the date the photo was taken and update the creation date of the file. But this isn’t easy to do manually for lots and lots of newly converted DNG files. So I’ve made a script to do it automatically for all DNG files found under a defined path:

dngfiles=$(find "$1" -name "*.dng" | sed 's/ /\\-/g' | sed 's/dng\\-/dng /g')
for entry in $dngfiles
fixentry=$(echo $entry | sed 's/\\-/ /g')
output=$(/Applications/Affinity\ -createdate "$fixentry" | grep Create | sed s/://g | sed s/\ //g | sed 's/^CreateDate//' | sed 's/..$//')
touch -t $output "$fixentry"
ls -l "$fixentry"

Let’s say we call the script To run the script, you simply give the path to check. For example:

$ ./ /Volumes/Photos/Archive/2015
Categories: Mac, Photography Tags: , ,