MPAW MPAW - 1 month ago 21
Bash Question

How to remove files not containing string? - Windows

i want to remove all files not containing string "EXAMPLE STRING" in current folder.
How to do that?

I tried to, somehow, change this:

for /f "eol=: delims=" %F in ('dir /b /a-d * ') do find "EXAMPLE STRING" %F > nul && del "%F"


But this deletes files with my string, not without.
How to make a command that would delete all files without string "EXAMPLE STRING"?

Answer

find "EXAMPLE STRING" %F > nul &if errorlevel 1 del "%F"