How to delete specific files?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
emi
Posts: 1
Joined: 07 Oct 2013 05:14

How to delete specific files?

#1 Post by emi » 07 Oct 2013 05:34

Hi guys, I have a problem needing solving and little batch coding experience.

Here is basically what I am trying to do:

for each file in subfolder "RAW"
IF NOT(.raw file has .jpg file one folder up that has the same name.)
delete current file



Description of situation:
This has to do with how I organize my DSLR pictures.

- When copying pictures from the camera I have a folder containing both .jpg and .raw of the same images.
- I then put the .raw files in a subfolder called RAW to separate the .jpg and .raw files.
- I then browse through the .jpg files and delete whatever pictures I don't need.
- The situation is now that I have the .jpg files I want to keep, but the RAW subfolder still contains all the original files.
- I want the RAW folder to only contain .raw files that has a .jpg file that has the same name one folder up in the file structure.
- Result should be that both folders contain the same amount of picture files, one folder with jpg and one with raw.

Any help on this "Clean up routine" would be greatly appreciated. Because the way it is now I have deleted alot of jpg files, but havent bothered to clean up the raw files. Since raw files take approx 4 times the harddisk space of a jpg my harddrive is now full and I really need to get this working so I can do a proper cleanup!

dwngrt
Posts: 26
Joined: 07 Oct 2013 05:14
Location: The Netherlands

Re: How to delete specific files?

#2 Post by dwngrt » 07 Oct 2013 05:39

Hello there Emi :D

I will try to help you with this script :)

So if i am correct, you have a folder filled with .jpg files and .raw files.
But you want the .jpg files in a sub-directory and the same with the .raw files in another one.

if this is all you need, then it's really easy to solve this :D
let me know ;)

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

Re: How to delete specific files?

#3 Post by foxidrive » 07 Oct 2013 05:47

This will echo onto the console the names of the .raw files that don't have a matching .jpg file in the parent folder.

Remove echo to enable the deletion after you test it.

Code: Select all

@echo off
cd /d "c:\pictures\raw"
for %%a in (*.raw) do if not exist "..\%%~na.jpg" echo del "%%a"

Post Reply