I have a SSD with several partitions.
I need to work at J:\ and I need to delete everything inside J:\, except the following folders:
J:\System Volume Information  
J:\$RECYCLE.BIN  
J:\New  
J:\Old Stuff  
And the following sub-folders:
J:\Papers\Folder  
J:\Room\Main Documents  
J:\Year\Origin\Part  
J:\Year\Origin\Part Two  
After reading a lot, I wrote:
@ECHO OFF 
SETLOCAL 
SET "sourcedir=J:\"
SET "keepdir=System Volume Information"
SET "keepdir=$RECYCLE.BIN"
SET "keepdir=New"
SET "keepdir=Old Stuff"
SET "keepdir=Papers\Folder"
SET "keepdir=Room\Main Documents"
SET "keepdir=Year\Origin\Part"
SET "keepdir=Year\Origin\Part Two"
FOR /d %%a IN ("%sourcedir%\*") DO IF /i NOT "%%~nxa"=="%keepdir%" RD /S /Q "%%a"
GOTO :EOF
Unfortunately, the code above deletes everything inside J:\.