Archive

Posts Tagged ‘DNG’

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:

#!/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: , ,

Deleting RAW files after converting to DNG on a Mac

August 11th, 2015 No comments

Recently, I decided to convert all my old RAW files to DNG.  This can be done from within Lightroom or with Adobe’s free DNG Converter.  In Lightroom, you have the option to have your old RAW files deleted automatically after conversion.  However, this option is unfortunately missing in the DNG Converter.

One way to do this manually is by opening a terminal session on your Mac and entering this command:

$ find [path] -name "*.[RAW extension]" -type f -delete

The above command will recursively go through all the subfolders and files under the defined path and delete all files with the defined file extension. To be safe though, you might first want to make sure that you have the same number of DNG files before deleting all the RAW files. For example:

$ find Photos/Archive/2015 -name "*.dng" -type f | wc -l
2290
$ find Photos/Archive/2015 -name "*.CR?" -type f | wc -l
2290
$ find Photos/Archive/2015 -name "*.CR?" -type f -delete

If you want to be really sure then it’s probably a good idea to first check that the DNG files are good before you delete all those RAW files. Perhaps view them all or import them to Lightroom. And when you delete all the RAW files, you might want to make sure that the converted DNG files exist. To do that I’ve written the follow shell script:

#!/bin/bash
rawfiles=$(find "$1"  -name "*.CR2" -o -name "*.ORF" | sed 's/ /\\-/g' |sed 's/CR2\\-/CR2 /g' |sed 's/ORF\\-/ORF /g')
echo Only deleting RAW files with equivalent DNG files...
for entry in $rawfiles
do
fixentry=$(echo $entry | sed 's/\\-/ /g')
dngfile=$(echo $fixentry | sed 's/...$/dng/g')
xmpfile=$(echo $fixentry | sed 's/...$/xmp/g')
if [[ -f "$dngfile" && -f "$fixentry" ]]
then
        echo Deleting $fixentry
        rm "$fixentry"
        if [[ -f "$xmpfile" ]]
        then
                echo Deleting $xmpfile
                rm "$xmpfile"
        fi
fi
done

If the script was named Delete_RAW.sh then you use it like so:

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