简体   繁体   English

Powershell 重命名-项目一次替换多个命名参数

[英]Powershell Rename-Item replace multiple naming parameters in one pass

I would like to replace a few filename parameters in one pass.我想一次性替换几个文件名参数。 Trying the following results in errors claiming the 'file already exists'.尝试以下操作会导致错误声称“文件已存在”。 Is there a way to name multiple replace parameters in a single pass?有没有办法在一次传递中命名多个替换参数?

file | Rename-Item -NewName { $_.Name -replace "parameter1", "X" , $_.Name -replace "parameter2", "Y" }

As requested, my comment as answer.根据要求,我的评论作为答案。

You can daisy-chain -replace , so in this case您可以菊花链-replace ,所以在这种情况下

$_.Name -replace "parameter1", "X" -replace "parameter2", "Y"

Sorry for the short answer, but I'm on mobile now..对不起,简短的回答,但我现在在手机上..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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