Reputation: 273
I found a script that will delete all folders except a certain one
for /d %i in ("C:\test\*") do if /i not "%~nxi"=="test2" rd /q "%i"
How do you change this to add more folders that I don't want deleting?
Upvotes: 1
Views: 739
Reputation: 57252
@echo off
set "list=test1 test2 test3"
setlocal enableDelayedExpansion
set "delete=0"
pushd "C:\test\"
for /d %%i in (*) do (
set "delete=1"
for %%# in (%list%) do (
if /i "%%i" equ "%%#" (
set "delete=0"
echo %%i will be not deleted
)
)
if !delete!==1 (
rd /s /q "%%i"
)
)
popd
Upvotes: 1