2

How to: filter files by name and contents in Windows 7?

I need to find files named bob.xml recursively and leave (in the search results) only those that contain the phrase <gold>100</gold>

Can it be done under Windows 7 w/o using any external software (that I have to download and install)?

Best solution would use only Windows Explorer's search queries (the input in the upper-right corner)

Breakthrough
  • 34,847
Queequeg
  • 123
  • 4

1 Answers1

4

I'm not sure what your restrictions are in terms of 'external software' but you could use PowerShell, which is included on Win7. To open it you can just type 'PowerShell' in the Start search bar, or find it (I think) under Start > All Programs > Accessories > Windows PowerShell.

This set of commands will recursively find files named 'bob.xml' and will only return the names of those which contain the text '100'.

dir -filter bob.xml -recurse | select-string -pattern '<gold>100</gold>' -list | select-object -unique 'Path'

If you want to output those results to a text file so you can do something with it, this will do the trick.

dir -filter bob.xml -recurse | select-string -pattern '<gold>100</gold>' -list | select-object -unique 'Path' | out-file c:\temp\bob_search.txt

fussmonkey
  • 256
  • 2
  • 7