Quick python script to remove jpegs if raw exists

I have my EOS 80D set to save jpg and Raw files. However this means that when the files are imported I have a lot of wasted disk space. I’ve had this set for about 10 years which equates to about 80Gbytes of disk space. I thought I’d create this handy python scrypt to search through your Pictures folder for a file that has both a jpg and a cr2 file and then move the jpg to another folder – for review and/or potential deletion. NB This has worked on my Mac but please don’t hold me responsible if you accidently delete a precious folder.

import os
import shutil

raw_ext = '.CR2'
jpg_ext = '.JPG'
destination = '/Users/darren/Desktop/jpgs/'
source = '/Users/darren/Pictures/'
for root, subFolders, files in os.walk(source):
for file in files:
(shortname, extension) = os.path.splitext(file)
if extension == raw_ext:
if os.path.isfile(root + '/' + shortname + jpg_ext):
print 'Moving ' + root + shortname + jpg_ext
shutil.move(root + '/' + shortname + jpg_ext, destination)

Annoyingly WordPress doesn’t keep the indentations for python, so you can download the file here. Save the file in your home folder, unzip and edit the paths for destination and source and then run from terminal with python jpeg.py. You’ll need to crate your destination folder before you run the script. Comment out the last line with a # if you want to do a dry run!