How To Search For Text In a Directory with SubFolders

G

Guest

Hello.

I need to search for a text value in all files within a directory that has
sub folders.
I want to create a batch file to do this but have no idea how to do it.
I know I need the DIR /AD command that I can then use as a pipe to the
"Find "something" *.* > MyResults.txt".

I would like to pass in two arguments. 1st: path to my directory e.g. c:\temp.
2nd: what to search for.

The batch file should look something like this:
Rem Start of batch file
cd %1
dir /ad > MyDirs
for %%i in (MyDirs) do
cd %%i
find %2 *.* > C:\temp\MyResults.txt

Any help will be greatly apporeciated!

Rita
 
A

Ayush

RitaG wrote ::
Hello.

I need to search for a text value in all files within a directory that has
sub folders.
I want to create a batch file to do this but have no idea how to do it.
I know I need the DIR /AD command that I can then use as a pipe to the
"Find "something" *.* > MyResults.txt".

I would like to pass in two arguments. 1st: path to my directory e.g. c:\temp.
2nd: what to search for.

The batch file should look something like this:
Rem Start of batch file
cd %1
dir /ad > MyDirs
for %%i in (MyDirs) do
cd %%i
find %2 *.* > C:\temp\MyResults.txt

Any help will be greatly apporeciated!

Rita

try this-
@echo off
cd "%1"
for /f "tokens=*" %%X in ('dir /ad /b /s') do (
find "%2" "%%X\*.txt"
)


Good Luck, Ayush.
 
G

Guest

Wow!
Thanks Ayush, that worked perfectly for me.
I just piped the results to a file.

Rita

Ayush" <"ayushmaan.j[aatt]gmail.com said:
RitaG wrote ::
Hello.

I need to search for a text value in all files within a directory that has
sub folders.
I want to create a batch file to do this but have no idea how to do it.
I know I need the DIR /AD command that I can then use as a pipe to the
"Find "something" *.* > MyResults.txt".

I would like to pass in two arguments. 1st: path to my directory e.g. c:\temp.
2nd: what to search for.

The batch file should look something like this:
Rem Start of batch file
cd %1
dir /ad > MyDirs
for %%i in (MyDirs) do
cd %%i
find %2 *.* > C:\temp\MyResults.txt

Any help will be greatly apporeciated!

Rita

try this-
@echo off
cd "%1"
for /f "tokens=*" %%X in ('dir /ad /b /s') do (
find "%2" "%%X\*.txt"
)


Good Luck, Ayush.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top