Welcome to MSDN Blogs Sign in | Join | Help

jaredpar's WebLog

Code, rants and ramblings of a programmer.

Syndication

News

Now Reading

Expert F#

What's a better book to read when learning F#?

Essential WPF

Thus far the best book I've read on WPF. Gets right down to working with WPF and the goals/history.

Purely Functional Data Structures

Reading this book makes me feel like I'm back in college. It will really get your mind going and is best read with a whiteboard handy.


A smarter Select-StringRecurse

Previously I blogged about a recursive select-string function.  Recently I've extended it a bit.  I found the function to be very useful but when I encountered problems searching large directories that contained binary files.  Namely searching them usually returned a result of sorts and printing out the contents of a binary file caused my console to beep in a rather annoying fashion.  To fix this I added a new parameter that will perform a slightly smarter search by filtering out binary files.

function Select-StringRecurse()
{
    param ( [string]$text = $(throw "Need text to search for"),
            [string[]]$include = "*",
            [switch]$smart = $false)

    $smartRegex = "^\.(lib|exe|obj|bin|tlb|pdb)$"
    gci -re -in $include |
        ? { -not $_.PSIsContainer } |
        ? { (-not ($smart)) -or (-not ($_.Extension -match $smartRegex)) } |
        % { write-debug "Considering: $($_.FullName)"; ss $text $_.FullName }
}  

Published Monday, January 21, 2008 7:15 PM by Jared Parsons

Filed under:

Comments

# Fashion » A smarter Select-StringRecurse @ Monday, January 21, 2008 8:37 PM

PingBack from http://fashion.blogspace4you.info/?p=5535

Fashion » A smarter Select-StringRecurse

New Comments to this post are disabled
Page view tracker