Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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)

share|improve this question
    
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 '13 at 5:08
    
Out of interest, why the exclusion of external tools? –  snowdude Mar 13 '13 at 13:05
add comment

1 Answer

up vote 3 down vote accepted

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

share|improve this answer
    
PowerShell is just fine :) This works wonderfully! Can it be done using only Windows Explorer? –  Queequeg Mar 5 '13 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 '13 at 14:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.