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)

2
  • This would be easy to do from the command line: findstr /s "<gold>100</gold>" bob.xml or using a better search utility such as AstroGrep. It might be possible via Windows Search if the XMLs are indexed, but I'm not sure. Windows Search sucks for sure!
    – Karan
    Mar 6, 2013 at 5:08
  • Out of interest, why the exclusion of external tools?
    – snowdude
    Mar 13, 2013 at 13:05

1 Answer 1

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

2
  • PowerShell is just fine :) This works wonderfully! Can it be done using only Windows Explorer?
    – Queequeg
    Mar 5, 2013 at 14:31
  • I haven't been able to find a way to get Windows Explorer to do that. From what I've read (see link) the filters available depend on the type of file(s) showing in the results. Based on the answers in the link above, it doesn't look like file content is an option. That said, there could be a way, I'm just not familiar with it. As you might guess, I tend to use PS or other external tools when I need stuff like this. Good luck though!
    – fussmonkey
    Mar 5, 2013 at 14:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .