Monday, May 14, 2012

Deleting Orphan Raw Images after JPEGs have been Removed

I have been looking for a quick and dirty solution for removing unwanted files that have been copied from a camera that creates both raw and jpg files for shot pictures.

The python script below is very useful when you are working on a computer where no advanced tool, such as Adobe Lightroom, are available. You can use a simple image viewer, such as the one provided by Gnome or Irfanview on Windows, and browse through your images in a folder removing all unwanted pictures (the jpg version).

The python script below moves all raw images ("*.CR2")  with no corresponding jpg ("*.JPG") version to a sub folder "deleted". You can check than of the deleted folder and remove them manually. Alternatively replace "shutil.move(file, './deleted')" with "os.remove(file)" if you want to have the files deleted instead of moved.

The file extension naming is the one used by Canon. A modified version for other cameras might be not that difficult to write.