I have a few files and directories, (all directories contain files):
C:\\ABC
│ file1.txt
│
├───folder1
│ oneormorefiles.ext
│
├───folder2
│
I would do it the following way:
rem // Change to the target root directory:
pushd "C:\ABC" && (
rem // Loop over all immediate sub-directories:
for /F "delims= eol=|" %%F in ('dir /B /A:D "*"') do (
rem // Remove sub-directory tree unless name is `log`:
if /I not "%%F" == "logs" rd /S /Q "%%F"
)
rem // Delete files located in the root directory:
del /A /F /Q "*.*"
rem // return to the original directory:
popd
)