Skip to content

Instantly share code, notes, and snippets.

@matthewjberger
Forked from jongalloway/RecursiveReplace.ps
Created June 16, 2016 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewjberger/7c026db8e8c29127317e573af8621355 to your computer and use it in GitHub Desktop.
Save matthewjberger/7c026db8e8c29127317e573af8621355 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