MPAW MPAW - 6 months ago 74
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"?


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