Skip to content

Instantly share code, notes, and snippets.

@RhysC
Created August 1, 2011 09:38
Show Gist options
  • Save RhysC/1117863 to your computer and use it in GitHub Desktop.
Save RhysC/1117863 to your computer and use it in GitHub Desktop.
String and file helpers
function Select-UniqueChildrenWithStringPattern {
param($path, $pattern)
Get-ChildItem $path -Recurse |
Select-String -Pattern $pattern |
Select-Object Path |
Get-Unique
}
function String-ReplaceRecursive {
param($path, $pattern, $replaceValue)
(Select-UniqueChildrenWithStringPattern $path $pattern) |
% {
$content = Get-Content -path $_.Path
$content | % { $_ -replace $pattern , $replaceValue } | Set-Content $_.Path
}
}
function Copy-ItemRecursiveWithExcludes{
param($source, $dest, $exclud)
Get-ChildItem $source -Recurse -Exclude $exclude |
Copy-Item -Destination {Join-Path $dest $_.FullName.Substring($source.length)}
}
#Examples
#String-ReplaceRecursive . "..\\src\\" "..\BuildOutput\"
#Copy-ItemRecursiveWithExcludes . "C:\scratch\" @('*.svn','*.zip')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment