Alex Rivera | Logout

How to delete *.* excluding some extensions?

Asked 2012-02-24T02:06:27.503
11

I'm trying to make a batch file on Windows for deleting all the files in the current directory but excluding 4 file extensions (log, sdb, SDK, bat).

I have tried the Forfiles command on Windows but this delete everything on my current folder (even the bat file). My command is:

@ECHO OFF
FORFILES /M *.* /C "cmd /c IF NOT @ext=="sdb" (IF NOT @ext=="sbk" (IF NOT @ext=="log" (IF NOT @ext=="bat" DEL @FILE)))" /Q

How can I make it work?

Edit
Report

1 Answer

5

Also, you can do something like this:

@echo off
attrib -r -s *.*
attrib +r +s *.sdb
attrib +r +s *.sbk
attrib +r +s *.log
attrib +r +s *.bat
del *.* /S /Q
attrib -r -s *.sdb
attrib -r -s *.sbk
attrib -r -s *.log
attrib -r -s *.bat

-- Mario

answered 2012-02-24T19:19:40.670

Your Answer