Delete all folders except… (*.BAT)

限于喜欢 提交于 2019-12-01 08:08:22

This should help you:

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

Or simply copy MYFOLDER to a temp folder, delete all files, and copy back MYFOLDER. Unless MYFOLDER is huge and takes time to copy, this should work just as good.

mihai_mandis

Dir all folders and check one by one if it is not MYFOLDER, if is not - delete it. Please remove echo when running the real job.

for /d %%i in (C:\Parent\*) do (
    if /i "%%i" NEQ ".exe" echo rd /S /Q %%i
)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!