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

Cmd 使用Windows findstr列出不包含字符串的文件,cmd,findstr,Cmd,Findstr,从Windows CMD我可以使用 findstr -m subroutine *.f90 列出后缀为.f90且包含“subroutine”的所有文件。要列出所有不包含该字符串的.f90文件,我可以执行以下操作 dir /b *.f90 > files.txt findstr -m subroutine *.f90 > files_with_string.txt 然后编写一个脚本,列出files.txt中的行,这些行在带有_string.txt的文件_中找不到。有更优雅的方法吗?

从Windows CMD我可以使用

findstr -m subroutine *.f90
列出后缀为.f90且包含“subroutine”的所有文件。要列出所有不包含该字符串的.f90文件,我可以执行以下操作

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

然后编写一个脚本,列出files.txt中的行,这些行在带有_string.txt的文件_中找不到。有更优雅的方法吗?

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

for %a in (*.f90) do @findstr "subroutine" "%a" >nul || echo %a
(以上是命令行语法。要在批处理文件中使用,请使用
%%a
而不是
%a
(所有三种情况))