![](/img/trans.png)
[英]Read a file and then based on file content names, move the file from one folder to another using Powershell script
[英]How to move a file to another directory and change the content of it using pipe in one line in Powershell?
下面的代码不起作用。 但是在两行作品中分别进行。
移动项目文件.txt \same-directory | Set-Content -Path \same-directoy -Value "新内容"
没有开关-PassThru
的Move-Item cmdlet 不返回任何内容,因此在这种情况下,不会通过 pipe 将任何内容发送到Set-Content
cmdlet。
如果您真的想以单线方式执行此操作,请使用
Move-Item -Path 'D:\file.txt' -Destination 'D:\some-directory' -PassThru | Set-Content -Value "New content"
由于现在我们实际上是在对移动的 object 进行管道传输,因此需要省略Set-Content
的-Path
参数。
当然,目标文件夹D:\some-directory
需要存在
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.