Home > Mac, Photography > Changing created/modify date of DNG files

Changing created/modify date of DNG files

August 16th, 2015 Leave a comment Go to 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:

#!/bin/bash
dngfiles=$(find "$1" -name "*.dng" | sed 's/ /\\-/g' | sed 's/dng\\-/dng /g')
for entry in $dngfiles
do
fixentry=$(echo $entry | sed 's/\\-/ /g')
output=$(/Applications/Affinity\ Photo.app/Contents/Resources/exiftool -createdate "$fixentry" | grep Create | sed s/://g | sed s/\ //g | sed 's/^CreateDate//' | sed 's/..$//')
touch -t $output "$fixentry"
ls -l "$fixentry"
done

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

$ ./Fix_DNG_date.sh /Volumes/Photos/Archive/2015
Categories: Mac, Photography Tags: , ,
  1. No comments yet.
  1. No trackbacks yet.
*