Skip to content

Instantly share code, notes, and snippets.

@anth12
Last active October 3, 2024 09:27
Show Gist options
  • Save anth12/6a4f076d021113482127 to your computer and use it in GitHub Desktop.
Save anth12/6a4f076d021113482127 to your computer and use it in GitHub Desktop.
Replaces all instances (file name and contents) of 'X' with 'Y'. Used for template project config.
$match = Read-Host "What would you like to replace?"
$replacement = Read-Host "And what would you like '"$match"' replacing with?"
$files = Get-ChildItem $(get-location) -filter *$match* -Recurse
$files |
Sort-Object -Descending -Property { $_.FullName } |
Rename-Item -newname { $_.name -replace $match, $replacement } -force
$files = Get-ChildItem $(get-location) -include *.cs, *.csproj, *.sln, *.js, *.scss, *.cshtml, *.razor, *.prompty -Recurse
foreach($file in $files)
{
((Get-Content $file.fullname) -creplace $match, $replacement) | set-content $file.fullname
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment