зеркало из https://github.com/dotnet/pinvoke.git
35 строки
1.1 KiB
PowerShell
35 строки
1.1 KiB
PowerShell
function Replace-Placeholders {
|
|
[CmdletBinding()]
|
|
param(
|
|
[Parameter(Mandatory=$true)]
|
|
[string]$Path,
|
|
[Parameter(Mandatory=$true)]
|
|
[string]$LibraryName,
|
|
[Parameter(Mandatory=$true)]
|
|
$Replacements
|
|
)
|
|
|
|
Get-ChildItem -Recurse $Path -File |% {
|
|
$content = Get-Content -Path $_.FullName
|
|
$Replacements.GetEnumerator() |% { $content = $content -replace $_.Key,$_.Value }
|
|
Set-Content -Path $_.FullName -Value $content -Encoding UTF8
|
|
|
|
if ($_.Name -match 'LIBNAME') {
|
|
$NewLeafName = $_.Name -Replace 'LIBNAME',$LibraryName
|
|
Rename-Item $_.FullName $NewLeafName
|
|
}
|
|
}
|
|
|
|
# Rename directories
|
|
Get-ChildItem -Recurse $Path -Directory |% {
|
|
if ($_.Name -match 'LIBNAME') {
|
|
$NewLeafName = $_.Name -Replace 'LIBNAME',$LibraryName
|
|
Rename-Item $_.FullName $NewLeafName
|
|
}
|
|
}
|
|
|
|
# Finally, rename $Path itself
|
|
$NewLeafName = (Split-Path -Leaf $Path) -Replace 'LIBNAME',$LibraryName
|
|
Rename-Item $Path $NewLeafName
|
|
}
|