Last active
March 5, 2021 13:18
-
-
Save Himura2la/c76e7f4add7280aaa4bfd60fa4472782 to your computer and use it in GitHub Desktop.
Replace all occurrences of a string in a directory
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 MassReplace { | |
param ( | |
[Parameter(Mandatory=$true)] [string] $Path, | |
[Parameter(Mandatory=$true)] [string] $Include, | |
[Parameter(Mandatory=$true)] [string] $FindString, | |
[Parameter(Mandatory=$true)] [string] $ReplaceString | |
) | |
Get-ChildItem $Path -Include $Include -Recurse | |
| Select-String $FindString -SimpleMatch | |
| Group-Object -Property Path | |
| ForEach-Object { | |
(Get-Content -LiteralPath $_.Name -Raw).Replace($FindString, $ReplaceString) | |
| Set-Content -NoNewline -LiteralPath $_.Name | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment