Search code examples
windowsbatch-filefindstr

Windows command line to findstr 1 level of subdirectory down


Looking for the command line (or batch) that will do the following,

I have 3 levels of directories and need to search for a specific string contained in text files, searching all files, 1 level subdirectory down.

So I know this will recursively search for the string

findstr /S "STRING" *

But I don't want the search to go father than only 1 subdirectory level down.

Seems like a simple thing but I could not find anything solid. The closest thing I could find was something like this thread..

windows batch to recursively scan files in 1 level subfolders

However, before going batch is there a simpler (command line) way to this rather, apparently simple task?

Thanks for your time!


Solution

  • This should do it from the command line and write file.log into the current folder

    for /d %a in (*) do findstr "STRING" "%a\*">>file.log