Batch script to delete all folders except of "Starts with"

Viewed 2224

I have a folder with several subfolders. Structure is like:

  • C:\foo
  • C:\foo\web.foo
  • C:\foo\web.bar
  • C:\foo\win.foo
  • C:\foo\win.bar
  • C:\foo\mobile.foo
  • C:\foo\mobile.bar

I sometimes wish to delete the folders with its containing files with following batch script:

rmdir C:\foo /s /q

Here it didn't matter that the whole folder C:\foo was deleted completely.

But now I only want to delete only the subfolders of C:\foo with its containing files, which DO NOT start with "web.".

Do you have any good solution for this?

2 Answers
Related