[英]Append to file names in a loop with Powershell
Desired functionality 所需功能
file1.txt -> file1.txt.deploy
file2.txt -> file2.txt.deploy
Attempt #82 尝试#82
Get-ChildItem | ForEach-Object {
Rename-Item -NewName { $_.Name + ".deploy" }
}
Cannot evaluate parameter NewName because its argument is specified as a script block and there is no input
What am I doing wrong? 我究竟做错了什么?
If you use ForEach-Object
you need to pipe in the actual object with $_
: 如果使用
ForEach-Object
,则需要使用$_
传递实际对象:
Get-ChildItem | ForEach-Object {
Rename-Item $_ -NewName { $_.Name + ".deploy" }
}
Or just skip the ForEach-Object
as BartekB mentions in comments: 或者就像BartekB在评论中提到的那样跳过
ForEach-Object
:
Get-ChildItem | Rename-Item -NewName { $_.Name + ".deploy" }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.