MPAW MPAW - 1 year ago 110
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 Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download