相关疑难解决方法(0)

查找和替换文件失败

我试图使用以下方法在文件中查找和替换.

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
Run Code Online (Sandbox Code Playgroud)

但我总是得到错误.

Set-Content:进程无法访问文件'c:\ program files(x86)\ MyProj\web.config',因为它正由另一个进程使用.

该文件不会在任何地方打开.我认为Get-content尚未发布该文件.

为什么会这样?如何在同一个文件中查找和替换没有问题?

powershell powershell-2.0

27
推荐指数
1
解决办法
9984
查看次数

标签 统计

powershell ×1

powershell-2.0 ×1