How can I delete RAW files that no longer have a matching JPEG?
Asked 4/9/2012
3 views
2 answers
0
I shoot RAW+JPEG (NEF + JPG). After reviewing large batches of photos, I often delete the JPEGs and end up with leftover RAW files that I no longer want. Is there a safe way to find and remove RAW files that don't have a matching JPEG in the same set? A script or command-line solution would be ideal.
Originally by Photography Stack Exchange contributor. Source · Licensed CC BY-SA 4.0
Photography Stack Exchange contributor
14y ago
2 Answers
9
I wrote a script in Python to do the work for me. It's called remove-orphaned-raw-images.py and I published it on Github.
Basically it iterates over all the files in a given folder and moves orphaned raw images (in my case *.CR2 files with no matching JPEG) to a backup folder. Optionally you can tell the script to actually delete the files.
Here is an outline of the algorithm:
- Get a list of all the files in the selected directory.
- Sort those files into RAW and JPEG files (append them to separate lists).
- Check for each item in the RAW images list that a match exists in the JPEG list;
if not, append this image to a list of orphaned raw images. - Move the images in the list of orphaned images to a backup folder
(or directly delete them if explicitly wanted).
The tool will tell you how to use it when run with the help option -h on the command line.
This problem also occured to me, which is why I wrote this tool. I'm using my DSLR to take JPEG or RAW+JPEG images, never only RAW. When sorting out blurry or otherwise bad shots, I use the JPEGs to quickly take a look at them and delete the bad ones. This leaves me with left over RAW images of which I deleted the matching JPEGs (for a reason).
Originally by user14015. Source · Licensed CC BY-SA 4.0
user14015
13y ago
0
Generated from our catalog & community — verify before relying on it.
Yes. A common way to do this is with a small script that compares base filenames: list all JPEGs, list all RAW files, and for each RAW file check whether a JPEG with the same filename exists. If not, treat that RAW as an orphan.
The safest approach is to move orphaned RAW files to a backup folder first, then delete them only after you verify the results. Community answers suggested both Python scripts and a Windows batch-file workflow.
General process:
- Scan the folder (or folders).
- Separate JPEG and RAW files by extension.
- Match files by filename without extension.
- Move unmatched RAW files to a backup folder, or delete them if you’re certain.
Be careful:
- Back up first.
- Matching by filename assumes your RAW and JPEG pairs share the same base name.
- Recursive scripts can affect files in subfolders too.
- If you have duplicate filenames from different cameras or folders, a simplistic script may produce wrong matches.
A Python script is usually the most flexible and safest option because you can preview or move files before deleting them.
Recommended products
UniqueBot
AI14y ago
Your Answer
Related Questions
How can I delete JPEGs only when a matching RAW file exists?
How can I delete RAW files only when a matching JPEG exists?
Can a Nikon D5600 delete only the RAW file from a RAW+JPEG pair in-camera?
Should I delete archived RAW files if I only ever use the JPEGs?
Why do my Fujifilm X100S RAW files appear to have no EXIF, and can I sync metadata from matching JPEGs?