Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
264 views
in Technique[技术] by (71.8m points)

batch file - Delete all folders except 123, 1234 and 12345

With below I can delete all folders in C:Temp expect folder 123 but I want to add another folder 1234 and 12345 that should not be deleted once you run the script, can some help me how i can add folder 1234 & 12345.

pushd "C:Temp" || exit /B 1
for /D %%D in ("*") do (if /I not "%%~nxD"=="123" rd /S /Q "%%~D")
for %%F in ("*") do (del "%%~F")
popd
question from:https://stackoverflow.com/questions/65936171/delete-all-folders-except-123-1234-and-12345

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
for /D %%D in ("*") do (
 set "zapme=Y"
 for %%O IN (123 1234 12345) do if /I "%%~nxD"=="%%O" set "zapme="
 if defined zapme rd /S /Q "%%~D"
)

using zapme as a flag.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...