How can I delete JPEGs only when a matching RAW file exists?

Asked 10/14/2011

2 views

2 answers

0

I have a large photo archive stored in dated subfolders under one main import directory. Older images are JPEG-only, but many newer folders contain both JPEG and RAW versions of the same shot. Before importing into Lightroom, I want to remove only the JPEG files that have a matching RAW file in the same folder, while keeping standalone JPEGs. Is there a way to do this in Lightroom, or should I use a Windows command/script to scan subfolders and delete or move only the duplicate JPEGs?

Originally by Photography Stack Exchange contributor. Source · Licensed CC BY-SA 4.0

Photography Stack Exchange contributor

14y ago

2 Answers

29

On Windows, go to the folder, and run this in a command prompt:

for /f "delims==" %r in ('dir /b *.nef') do del "%~dpr%~nr.jpg" 2> nul

Basically, it goes through the current folder, runs through the NEF files, and deletes the JPG if present. It ignores any errors if the JPG is not there.

If you want subfolders, include /s in the dir command.

Originally by user6881. Source · Licensed CC BY-SA 4.0

user6881

14y ago

0

AI Answer

Generated from our catalog & community — verify before relying on it.

Lightroom isn’t the best tool for this cleanup before import. The community solutions point to doing it at the file-system level instead.

On Windows, a simple command-line approach is to loop through RAW files and delete the same-named JPG if it exists. For Nikon NEF files, one answer suggested:

for /f "delims==" %r in ('dir /b *.nef') do del "%~dpr%~nr.jpg" 2> nul

Add /s to the dir command if you want it to process subfolders too.

If you want something safer and more flexible, use a Python script instead. The shared scripts can:

  • work recursively through subfolders
  • match files only within the same folder
  • handle case-insensitive extensions
  • support multiple RAW extensions
  • move JPGs to a backup/wastebasket folder instead of deleting immediately

That last option is the safest, since you can verify results before permanently removing anything. In short: use a script or command outside Lightroom, and ideally move the JPEGs first rather than deleting them outright.

UniqueBot

AI

14y ago

Your Answer