Delete JPG if RAW using ExifTool command line?

Started by HiTach, July 25, 2018, 02:35:06 PM

Previous topic - Next topic

HiTach

I am looking to create an ExifTool command line to remove JPG images with the same name as raw images in the same folder.
I suspect many photographers collect both until they have become proficient at processing raw, or would like to recover the disk space.
It could also work in reverse, deleting raw images when a final jpg is created.

I envision something like:
if exists (filename.nef && filename.jpg) delete filename.jpg

It could include a test for same capture time just to make sure.

Case-insensitive
Add recursion as needed
repeat for .cr2, .arw etc.

I have reviewed many examples, but they mostly deal with internal exif tags, and have made my own time shift command lines.
I also searched but didn't find a solution so far.

Thanks for any help!

Phil Harvey

Try this:

exiftool -directory=trash -srcfile %d%f.jpg -ext nef -ext cr2 -ext arw DIR

This should move all ".jpg" images to a "trash" folder if there is an NEF, CR2 or ARW (case insensitive) with the same name in the same folder.  You'll have to repeat this for ".JPG" images if your filesystem is case sensitive.

Note that you will get an error if there are two JPG's with the same name.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

HiTach

#2
Thanks for the fast reply Phil!

This works, except when I use -r for recursion.
The source is recursive, but the destination is always /trash creating duplicate errors (as you noted) and leaving the source behind.

Ideally then, I would like to recreate the source folder structure in the destination.

If that's not possible, (I feel certain it is, as I can create destination folders based on date and tags etc.,) then append characters to make each duplicate file unique, or, overwrite the destination copy if the image files are identical, so the source is still moved.

I spent several hours in the docs and examples but couldn't find the solution, hope you can help.

Phil Harvey

To create the same directory structure in the trash:

exiftool -directory=trash/%d -srcfile %d%f.jpg -ext nef -ext cr2 -ext arw DIR

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

HiTach