# Solved: findstr Across Multiple File Types



## corykv (Sep 23, 2009)

Using findstr to find strings is fairly easy. I am trying to search recursively through a path, but only want to check one of three file types: *.java, *.properties or *.xml.

I know how to do one:

findstr /pinsc:"my weird search string" *.java


But how to tell findstr to look only in *.java, *.properties and *.xml files without having to run findstr 3 times?

Thanks in advance.

corykv


----------



## Squashman (Apr 4, 2003)

Use the DIR cmd in a for loop.


```
FOR /F "tokens=*" %%A IN ('dir /b /a-d /s *.java *.properties *.xml') DO findstr /pinc:"my weird search string" "%%A"
```
I am not sure if you could also do this. I have never tried it.

```
findstr /pinsc:"my weird search string" *.java *.properties *.xml
```


----------



## ghostdog74 (Dec 7, 2005)

here's an alternative if you can download stuff. Go to  here  and download grep. then on the command line


```
C:\test>grep "line" *txt *.java
```
type grep --help on the command line for more options (which are way better than what findstr has)


----------



## Squashman (Apr 4, 2003)

ghostdog74 said:


> here's an alternative if you can download stuff. Go to  here  and download grep. then on the command line
> 
> 
> ```
> ...


How is that going to recurse through the sub-directories?


----------



## corykv (Sep 23, 2009)

Squashman, ghostdog,

Sometimes the simplest course of action is the easiest... Thanks for your help... this is what worked:


```
findstr /pinsc:"my search string" *.xml *.java *.properties
```
Squashman, I am a longtime user/lover of grep, unfortunately, I don't have the option on the machine I'm working on (corporate). Beautiful solution, though... none of the options I have ever seen have shown that ability --

Thanks, guys.

corykv


----------



## Squashman (Apr 4, 2003)

You could use GREP. It is a self contained EXE. No need to install it. Nobody is going to know it is there. Grep does have options to recurse directories but wasn't shown in GhostDog's example.


----------



## ghostdog74 (Dec 7, 2005)

Squashman said:


> How is that going to recurse through the sub-directories?


i guessed you have already found out, but just for completeness, the -R option does that job.


----------

