如何使 findstr 显示内联的完整文件路径?

How do I make findstr show the full file path inline?

当我使用 grep 时,我得到了一个匹配结果列表,其中包含所有子目录的完整文件路径。

当我使用 findstr 执行此操作时 - 我没有得到内联结果。

我的问题是:如何让 findstr 内联显示完整的文件路径?

阅读FINDSTR输出综合List of undocumented features and limitations of FINDSTR by Dave Benham aka dbenham:

... When printed, the fileName will always include any path information provided. Additional path information will be added if the /S option is used. The printed path is always relative to the provided path, or relative to the current directory if none provided.

因此,提供绝对路径。例如:而不是

findstr /S /M /I /C:"string being searched for" *.txt

使用

findstr /S /M /I /C:"string being searched for" "%CD%\*.txt"

当然上面例子给出的所有/S /M /I /C:开关都是可选的:

d:\bat\files>findstr "success" *.txt
netuser.txt:The command completed successfully.
typeperf.txt:The command completed successfully.

d:\bat\files>findstr "success" "%CD%\*.txt"
d:\bat\files\netuser.txt:The command completed successfully.
d:\bat\files\typeperf.txt:The command completed successfully.
findstr "search string" %cd%\*