How can I quickly delete all RAW files but keep Orphan RAW files?

davdavdav

Member
Messages
11
Reaction score
0
I shot for a while using jpg+RAW and at some point must have deleted one or the other of a particular shot. I now want to free up space on my laptop and all RAW files but keep any RAW that don't have corresponding jpgs.

Is there a way I can do this without having to go through each one?

(I do not use any apps to organise my photos - not aperture/lightroom/iPhoto etc)
 
You can do it with a shell script.

What is the format of your raw and jpg file names?

Are they all in one folder, or in multiple folders? If the latter, what is the arrangement of the folders?
 
You can do it with a shell script.

What is the format of your raw and jpg file names?

Are they all in one folder, or in multiple folders? If the latter, what is the arrangement of the folders?

--
John Bandry
Hi John

I don't know what a shell script is but I'm pretty capable at following instructions.

The format of the files are NUMBER.jpg and NUMBER.cr2

Where I have both the NUMBER should be the same.

All my RAW files are in subfolders within my Mac "Pictures" folder.
 
The following script is quite simplistic, but should work if you follow instructions!

run TextEdit (it's in /Applications/Other by default); copy and paste in the following 7 lines into a new file:

JPGList=`find ~/Pictures/cleanup -name '*jpg' -print`

for Image in $JPGList do

Folder=`dirname $Image`

Filename=`basename $Image jpg`

RAW=$Folder$'/'$Filename'cr2'

rm $RAW

done

Select "Save" from the file menu. In the "save as" box, type 'rawdelete' (without apostrophes) as the filename. Uncheck the box at the bottom marked 'if no extension is provided, use txt'. Select your home directory (you user name in the list of folders on the left with the picture of the house) and click 'save'.

Close TextEdit

What this script will do is find all files in the Pictures/cleanup folder and below whose names end in .jpg and try to delete a file with the same name, but ending in .cr2, in the same location. It assumes that NONE of your folders or files have spaces or non-alphanumeric characters in their names. If they do, it will not work properly, so don't run it and let me know what file and folder names look like.

I've put the 'cleanup' bit in there to protect against oddities in your Pictures folder that I can't know about. What you need to do is create this folder (Pictures/cleanup) and use the Finder to drag each top-level image folder to it from the Pictures folder (move, not copy). You'll move them back afterwards.

Before you run the script, make sure you have a backup of your Pictures folder. I've tested the script, but I offer no guarantees :-)

Next, open a terminal window (Applications/Other/Terminal). In it, type:

chmod +x rawdelete

ls -l rawdelete

and you should see something very similar to:

belukha:~ John$ chmod +x rawdelete

belukha:~ John$ ls -l rawdelete

-rwxr-xr-x 1 John wheel 172 20 Nov 14:06 rawdelete

(note that's ls -ell, not I or 1)

Now type:

cat rawdelete

You should see the seven lines of script as above displayed. If not, something has gone wrong with the copy/paste, so delete the file 'rawdelete' and create it again.

To run the script, type (note it starts with a full stop):

./rawdelete

You'll see a number of messages saying 'no such file or directory'. This is where you have a jpg but no matching raw file.

You will not find any deleted files in your trash: they will just be gone.

When it's finished, check all is OK and the move the folders back from Pictures/cleanup to Pictures.

Please ask if anything is unclear.
 
Wow! That is incredibly generous of you John. Thank you so much. I will have a stab at this later today.

File names seem to be in the format "IMG_3521.CR2" or "f4488640.cr2"

My Folder names are all completely inconsistent. Most have spaces in, some have hyphens.
 
I've PM'd you. Don't be too eager - it needs a bit more thought to cope with the spaces, and cr2 or CR2.
 
David,

Instructions all as previously, except this is the (much longer) script to copy & paste into TextEdit. It will handle spaces in folder and file names, as well as raws being either .cr2 or .CR2. It still assumes that all your jpegs are .jpg and not .JPG or .jpeg. You don't need the lines that start with #. Don't forget to back up first. When you're done, you'll have a file "JPGList" which you can delete, as well as the script file.

#start of script ---

find ~/Pictures/cleanup -name '*jpg' -print > JPGList

echo Started `date`

while read Image

do

Folder=`dirname "$Image"`

Filename=`basename "$Image" jpg`

RAW1=$Folder$'/'$Filename'cr2'

RAW2=$Folder$'/'$Filename'CR2'

if [ -f "$RAW1" ]

then

rm "$RAW1"

fi

if [ -f "$RAW2" ]

then

rm "$RAW2"

fi

done < JPGList

echo Finished `date`

#end of script ---
 
My TextEdit doesn't give me the option to untick: 'if no extension is provided, use txt'.

When I 'Save As' the only file formats it allows in the format drop menu are: rtf, rtfd, html, webarchive, odt, docx, xml, doc
 
Oh well, that just makes it a tiny bit more complicated. Still, it's all good clean fun.

Instead of TextEdit, we'll use good old 'vi'.

Copy the script text, so you'll be able to paste it later.

Open a Terminal window. Type (without the quotes):

'vi rawdelete'

type the letter 'a' (nothing will be shown on the screen - only press the key once)

type cmd-v to paste the script text

press the escape key

hold down the shift key and press Z twice.

That will have created the script file. Now proceed as above.

PM me if you have problems.
 
My TextEdit doesn't give me the option to untick: 'if no extension is provided, use txt'.

When I 'Save As' the only file formats it allows in the format drop menu are: rtf, rtfd, html, webarchive, odt, docx, xml, doc
You just have to switch TextEdit into plaintext mode: cmd-shift-T or under Format -> Make Plain Text.
 
That didn't work for me. I probably executed your instructions incorrectly. I didn't get any of the "file not found" in the output. I just got a statement saying "finished" (or something like that) after about 10 seconds.

Rather than wasting any more of your time I've decided to simply delete my RAW files by searching cr2 in finder. (I realise that sounds mental to a lot of people but I tend to shoot in jpeg and try to get the shot right first time on camera rather than spend months of my life tweaking mediocre pics on a laptop). I managed to roughly isolate the RAW files that existed without jpegs and keep those saved.

Thanks for all you help John. I am simply astounded by peoples willingness to sacrifice time for strangers on forums.
 
I changed it to check whether the file exists before deleting it. Maybe it worked and did the job.
 

Keyboard shortcuts

Back
Top