Delete files that has not its JPG pair

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
lien2n45
Posts: 3
Joined: 30 Jul 2013 05:40

Delete files that has not its JPG pair

#1 Post by lien2n45 » 30 Jul 2013 05:46

I select my photos by deleting .jpg files. There are the RAW files .CR2 too. I would like to make a .bat file that removes all .CR2 files that its JPG pair has been deleted. For example, the folder has:

IMG1.JPG
IMG1.CR2
IMG2.CR2
IMG3.JPG
IMG3.CR2

The script will remove only the file IMG2.CR2

Thanks

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Delete files that has not its JPG pair

#2 Post by foxidrive » 30 Jul 2013 06:32

This should remove any CR2 file that does not have a JPG file with the same name. It is untested:

Remove the echo keyword after you test it. At the moment it will only echo the del command to the screen.

Code: Select all

@echo off
for %%a in (*.cr2) do if not exist "%%~na.jpg" echo del "%%a"

lien2n45
Posts: 3
Joined: 30 Jul 2013 05:40

Re: Delete files that has not its JPG pair

#3 Post by lien2n45 » 31 Jul 2013 08:57

It does not work. The console output is:

G:\...>if not exist "IMG_0041.JPG" echo del IMG_0041.CR2
...

G:\...>if not exist "IMG_0045.JPG" echo del IMG_0045.CR2
del IMG_0045.CR2


but it has not deleted any file

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Delete files that has not its JPG pair

#4 Post by Squashman » 31 Jul 2013 09:06

lien2n45 wrote:but it has not deleted any file

Reading is FUN! Re-Read Foxidrive's last post. Specifically the 2nd sentence.

lien2n45
Posts: 3
Joined: 30 Jul 2013 05:40

Re: Delete files that has not its JPG pair

#5 Post by lien2n45 » 31 Jul 2013 09:22

Aaah, ok. I got it. Thank you !!

Post Reply