使用 Windows findstr 列出不包含字符串的文件

Use Windows findstr to list files not containing a string

来自 Windows CMD 我可以使用

findstr -m subroutine *.f90

列出所有包含 "subroutine" 的后缀为 .f90 的文件。要列出所有不包含字符串的 .f90 文件,我可以执行类似

的操作
dir /b *.f90 > files.txt
findstr -m subroutine *.f90 > files_with_string.txt

然后编写脚本列出 files.txt 中未在 files_with_string.txt 中找到的行。有没有更优雅的方式?

findstr 中有一个 /v 选项,但这对这里没有帮助。
使用 for 循环处理每个文件,尝试查找字符串,如果找不到 (||),则回显文件名:

for %a in (*.f90) do @findstr "subroutine" "%a" >nul || echo %a

(以上是命令行语法。要在批处理文件中使用,请使用 %%a 而不是 %a(所有三个出现))