First, extract the directory names using dir /ad /b, then use findstr /v to filter out the directories that are not to be deleted, and finally use for to traverse the list.
@echo off
for /f "tokens=*" %%i in {'"dir d: /ad /b | findstr /i /v "Lgames Ngames 游戏菜单""') do rd /s /q "%%i"
Notes:
1. If there are Chinese characters in the findstr search string, the /i parameter needs to be added.
2. Considering that there may be spaces in the folder name, for /f should specify tokens=*, and when the rd command calls %%i, quotes should be added.
3. When using the output of a certain command as the loop condition of for, it is best to add another pair of double quotes inside the single quotes in the parentheses, which can avoid explicit character escaping and possible problems.