Created
May 3, 2012 16:36
-
-
Save i-e-b/2587057 to your computer and use it in GitHub Desktop.
Powershell pathspecs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function SpecToRegex($spec) { | |
$tmp = $spec.Replace("**", "[{A}]").Replace("*","[{B}]").Replace("\","[{C}]").Replace(".","[{D}]").Replace("?",".") | |
$tmp = $tmp.Replace("[{A}]",".*?").Replace("[{B}]","[^/\\]*").Replace("[{C}]","\\").Replace("[{D}]","\.") | |
"^$tmp$" | |
} | |
function FindFiles($in, $matching) { | |
$pattern = SpecToRegex($matching) | |
ls $in -Recurse | ?{$_.FullName -match "$pattern"} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ability to search for files with Ant-style wildcards; Use like
FindFiles -in "c:\stuff\" -matching "**\bin\*\*.dll"