Skip to content

Instantly share code, notes, and snippets.

@i-e-b
Created May 3, 2012 16:36
Show Gist options
  • Save i-e-b/2587057 to your computer and use it in GitHub Desktop.
Save i-e-b/2587057 to your computer and use it in GitHub Desktop.
Powershell pathspecs
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"}
}
@i-e-b
Copy link
Author

i-e-b commented May 3, 2012

Ability to search for files with Ant-style wildcards; Use like FindFiles -in "c:\stuff\" -matching "**\bin\*\*.dll"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment