I'm trying to loop through the thousands of folders I have and delete all the folders that are in a specific directory, without the specified name. Here is what I have worked on so far.
@ECHO OFF
SETLOCAL
SET "sourcedir=C:\testing\%%a\all\base\"
SET "keepfile=test.bat"
SET "keepdir=keepthisfolder"
FOR /d %%a IN ("%sourcedir%\*") DO IF /i NOT "%%~nxa"=="%keepdir%" RD /S /Q "%%a"
FOR %%a IN ("%sourcedir%\*") DO IF /i NOT "%%~nxa"=="%keepfile%" DEL "%%a"
GOTO :EOF
I've tried dozens on combinations of looping through the array, but only works when I give it an exact name. It does what I need this way, but that means doing it 1-by-1.