I have c:\JOE\ALAN, c:\JOE\ALBERT, c:\JOE\ANNA, c:\JOE\BOB
Launching from \JOE\, I want to findstr every file hat.txt that contains the string {cat} (no braces),
but only for DIRs that begin with the letter A; and include the DIR in the output, perhaps like this:
c:\JOE\ALAN\hat.txt I am a cat
c:\JOE\ANNA\hat.txt I am not a cat
(I do not want {c:\JOE\BOB\hat.txt I be cat} because BOB\ doesn't begin with A)
This output is also fine:
ALAN\hat.txt I am a cat
ANNA\hat.txt I am not a cat
I have foo.bat containing something like this:
Code: Select all
findstr /i /c:%1 %2
Code: Select all
FOR %%a in (A*.) do (foo.bat cat %%a\hat.txt)
I thought about FOR /R %%a in (hat.txt) do (foo.bat cat)
but I only want to process DIRs beginning with letter A.
Is this practical? Note,
- Everything (including the foo.bat wrapper) will be in a .bat, ergo the %%.
- I want the DIR name, not the filename on the output (I don't mind filename also though).
- I don't prefer, but don't mind if the DIR is on a separate line than the FINDSTR string output.
- FINDSTR /S may figure into the solution, but again I want to restrict which DIRs are searched.
- A clever solution might redirect or pipe feeding FINDSTR /D (or /F ?) but I avoid redirection, just my quirk, although I'm happy to append 2>NUL to suppress error messages (inside the .bat on the FINDSTR, not on the .bat issuance itself, right?)
I put a lot of details here so thanks just for reading through. I have found every participant here to be a great human being in their dedication to performance and excellence and accuracy and clarity, and that takes devoted effort which I am humbly grateful for.