The easiest way is to use FIND or FINDSTR with the /V
option to search for names that do not contain a string, and /I
to search in insenstive. Switch to FOR /F
and pipe results from DIR
to FIND
.
for /f "eol=: delims=" %F in ('dir /b /ad * ^| find /v /i "sample"') do del "%F"
change the value of% F to %% F, if used in a batch file.
source share