【发布时间】:2023-03-03 08:03:25
【问题描述】:
我正在尝试使用以下方法在文件中查找和替换。
Function Find-Replace ($FileFullpath, $FindString, $ReplacementString) {
Get-Content $FileFullpath |
Foreach-Object {$_ -replace $FindString, $ReplacementString } |
Set-Content $FileFullpath
}
Find-Replace "c:\program files (x86)\MyProj\web.config" $OldServiceName $NewServiceName
但我总是出错。
Set-Content : 进程无法访问文件 'c:\program files (x86)\MyProj\web.config' 因为它正被另一个进程使用。
文件没有在任何地方打开。我认为 Get-content 尚未发布该文件。
为什么会这样?如何在同一个文件中查找和替换没有问题?
【问题讨论】: