Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

batch: how to pipe dir output to findstr?

Tags:

batch-file

I would like to feed findstr with filenames without using the /f option, my script is like this:

@echo off
for /d /r %%d in (.) do dir /b /a-d "%%d"

And I want to check if a specific string exist in each file displayed by the dir command.

Thank you

like image 769
juRioqs75 Avatar asked Oct 24 '25 04:10

juRioqs75


1 Answers

What you are looking for is the option /F and its special value /, which reads the list of files to search from the console rather than from a file:

for /D /R %%d in (.) do dir /B /A:-D "%%d" | findstr /F:/ "search strings"

Since you are using the for loop just to return the directory tree, you could simply add switch /S to the dir command and dismiss the loop completely:

dir /B /S /A:-D | findstr /F:/ "search strings"
like image 151
aschipfl Avatar answered Oct 26 '25 03:10

aschipfl