$startPath = "."
# Text to replace
$old = "abc"
$new = "def"
Get-ChildItem -Path $startPath -Recurse -File |
# Skip any file inside folders that contain "control"
Where-Object {
($_.DirectoryName -notmatch "control") -and
($_.Name -match "config")
} |
ForEach-Object {
$file = $_.FullName
Write-Host "Processing: $file"
try {
# Read file content
$content = Get-Content $file -Raw
# Replace text
$updated = $content.Replace($old, $new)
# Write only if changed
if ($updated -ne $content) {
Set-Content -Path $file -Value $updated
Write-Host "Updated: $file" -ForegroundColor Green
} else {
Write-Host "No change: $file"
}
}
catch {
Write-Host "Skipped (binary or permission issue): $file" -ForegroundColor Yellow
}
}

0 Comments