繁体   English   中英

如何将文件移动到另一个目录并在 Powershell 的一行中使用 pipe 更改其内容?

[英]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 "新内容"

没有开关-PassThruMove-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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM