我找到了一个删除除了某个文件夹之外的所有文件夹的脚本
for /d %i in ("C:\test\*") do if /i not "%~nxi"=="test2" rd /q "%i"
如何更改此项以添加更多我不想删除的文件夹?
答案 0 :(得分:1)
@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