$file = 'G\*\configs.txt'
$find = '192.168.152.161:8011'
$replace = '{appconfigs.writes}'
(Get-Content $file).replace($find, $replace) | Set-Content $file
當我對所有檔案一起運行編輯腳本時,腳本將它們聯合起來,不會一一編輯。
我們可以做什么?
uj5u.com熱心網友回復:
您正在嘗試潛在地處理多個檔案。因此,您不能Get-Content立即使用。您需要將其包裝在一個回圈中。
這是有關如何執行此操作的示例。
$find = '192.168.152.161:8011'
$replace = '{appconfigs.writes}'
foreach ($File in Get-ChildItem -Path 'G\*\configs.txt') {
$Content = Get-Content -Path $File.FullName -Raw
#IndexOf to avoid using Set-Content on files that did not change
if ($Content.IndexOf($find) -gt -1) {
$Content.replace($find, $replace) | Set-Content $file.FullName
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/439104.html
上一篇:了解編碼語法
