up vote 1 down vote favorite
1
share [g+] share [fb]

Deleting items via the command-line is pretty easy.

del /options filename.extension

Now, suppose I want to delete all files which do not end with .jpg in a folder, how would I do that.

The thing is, I have a piece of software that converts all specified images to .jpg, but it leaves the originals, which I don't need anymore.

It would be much more efficient to execute a single statement, compared to doing multiple statements for every different filetype.

link|improve this question

feedback

3 Answers

up vote 3 down vote accepted

I would do it like this:

attrib +r *.jpg
del /q *
attrib -r *.jpg

This will first make all JPG files read-only, delete everything else (it will automatically skip read-only files), and then make the JPG files writeable again.

link|improve this answer
+1 because unlike Joey's works for any pattern! – ybungalobill May 1 '11 at 8:49
feedback

That's actually pretty easy.

You'll need for to iterate over the files and then simply look for the extension:

for %f in (*) do if not %~xf==.jpg del "%f"

should do the trick (code here).

link|improve this answer
thanks, but that alone depends on which map I'm using. – WebDevHobo Aug 30 '09 at 21:24
Map? – Joey Aug 31 '09 at 5:55
feedback

I know it's not answering your question directly, but have you looked at the options on your converter to see if:

a) It can delete the originals itself

or

b) Write the .jpg's to a new folder?

link|improve this answer
I doesn't have the direct option to do so. What it will do is overwrite the original if that was a JPG to begin with. But all others remain on the disk while a JPG of them is created. – WebDevHobo Aug 30 '09 at 21:22
@WebDevHobo - oh well, I'd go with Johannes suggestion then. – ChrisF Aug 30 '09 at 21:24
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.