Delete all folders except.... (*.BAT)

Falcon picture Falcon · Jan 10, 2014 · Viewed 15.1k times · Source

I would like to delete all folders except MYFOLDER found in a parent directory but I cant get it done?

for %%i in ("C:\Parent") do if not "%%i"=="MYFOLDER" del /f /q "%%i

could somebody please check the code?

(I'm using *.bat)

Answer

foxidrive picture foxidrive · Jan 11, 2014

This should help you:

for /d %%i in ("C:\Parent\*") do if /i not "%%~nxi"=="MYFOLDER" del /s /q "%%i"