Search code examples
command-linepathgrepdosfindstr

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


When I use grep I get a list of matching results with the full file path for all the child subdirectories.

When i do this with findstr - I don't get the inline results.

My question is: How do I make findstr show the full file path inline?


Solution

  • Reading FINDSTR Output in the comprehensive 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.

    Hence, provide absolute path. For instance: instead of

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

    use

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

    Of course, all /S /M /I /C: switches given in the above example are optional:

    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.