Search code examples
windowsbatch-filefor-loopcommand-prompt

Invert the sense of a FOR command?


With batch files, it's simple enough to process all files that share a string in their filename or extension, like:

FOR /R %F IN (*.EXE) DO @ECHO %F

But, what if I want to invert the sense of the file set? Like, process all files that don't end in .EXE?

FOR /R %F IN (anything-but-exe) DO @ECHO %F

I couldn't find anything that seemed to be what I was looking for by reading the output of FOR /?


Solution

  • This should be another option:

    FOR /R %F IN (*.*) DO @if /i not "%~xF"==".exe" ECHO %F