Skip to content

Instantly share code, notes, and snippets.

@davidalpert
Forked from jongalloway/RecursiveReplace.ps
Created December 29, 2011 13:50
Show Gist options
  • Save davidalpert/1534189 to your computer and use it in GitHub Desktop.
Save davidalpert/1534189 to your computer and use it in GitHub Desktop.
Recursive replace in files (PowerShell)
$find = 'jquery-1\.4\.4'
$replace = 'jquery-1\.5\.1'
$match = '*.cshtml' , '*.vbhtml'
$preview = $true
foreach ($sc in dir -recurse -include $match | where { test-path $_.fullname -pathtype leaf} ) {
select-string -path $sc -pattern $find
if (!$preview) {
(get-content $sc) | foreach-object { $_ -replace $find, $replace } | set-content $sc
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment