我可以使用 Windows CMD
findstr -m subroutine *.f90
列出所有后缀为 .f90 且包含“subroutine”的文件。要列出所有不包含字符串的 .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
(所有三个出现))
关于cmd - 使用 Windows findstr 列出不包含字符串的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52837843/