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
Delete files that has not its JPG pair
Moderator: DosItHelp
Re: Delete files that has not its JPG pair
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.
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"
Re: Delete files that has not its JPG pair
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
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
Re: Delete files that has not its JPG pair
lien2n45 wrote:but it has not deleted any file
Reading is FUN! Re-Read Foxidrive's last post. Specifically the 2nd sentence.
Re: Delete files that has not its JPG pair
Aaah, ok. I got it. Thank you !!