Separate files with identical names but different extensions

Problem №1

When you’re taking photos with your camera set to Raw+Jpeg, your phone or camera places both file types into the same folder (e.g., IMG_0001.dng / IMG_0001.jpg). It would be rather convenient if your computer could automatically sort the raw and jpeg files into separate folders. Or at the very least, move all the jpeg copies into a separate folder.

Problem №2

If you’ve got your phone set to Raw+Jpeg mode, any selfies you take (which are usually just JPEG) get mixed up with the raw+jpeg files.
It would be quite useful if this could be automatically sorted as well.

The solution!

Here’s a link to a script for Mac users — Files-separation-script.zip. A quick double-click on it and the first problem is sorted straight away (more on the second problem later). If the file doesn’t run, you’ll need to give it execution rights (open Terminal.app, type “chmod 777”, add a space, and drag the downloaded file into the terminal, as shown in the image below).

Как дать права на запуск в Terminal.app

The crux of the script is that it finds files in a folder with the same names but different extensions, and separates one file format from another into a separate folder.
You’ll need to tweak the script a bit first. I’ve added some explanatory comments in the file, but I’ll break it down line by line here.

So.

Firstly, SOURCE_DIR=/Volumes/MainHDD/Photos/2016/10/California is the source folder where the script will do its digging. To quickly add a folder here, you can right-click on it in Finder and select Copy Path » Terminal Path. Erase everything after the “=” sign and press CMD+V (paste from clipboard).

Как скопировать путь к папке

Next, DEST_DIR=/Volumes/MainHDD/Photos/2016/10/California/JPEGS is where the script will place the jpeg copies of the photos. The script will create this folder itself, so there’s no need to create it in Finder.

And a little trick: this script currently looks for DNG+JPG pairs. If you replace “.dng” with, say, “.cr2” in the script, it will look for Canon files. You’ll need to make this change on line 17. The script can also look for any file types. You just need to change the extensions on line 17 (.jpg/.dng) and also on line 13 (.jpg).

Regarding the Second Problem

The script only moves files with the same names but different extensions into a separate folder. This means that selfies, which don’t have raw file duplicates, stay mixed in with the raw files. By sorting the file list by type in Finder, you can easily separate these individual jpeg files and manually move them somewhere else.

P.S.

If you’re a dab hand at writing Mac programs and fancy helping out, we could team up and create a GUI for the script. I can handle the UX/UI (I’ve already got a prototype). Drop me a line on Telegram or here on the site.