我的文件夹中有一些图片
van-map-PE 100-1.png
van-map-PE 200-8.png
van-map-PE 160-2.png
van-map-PE 400-6.png
现在,我想删除PE xxx-
之间的所有空格,并用-
代替
van-map-PE-100-1.png
van-map-PE-200-8.png
van-map-PE-160-2.png
van-map-PE-400-6.png
我在Power Shell中使用了此命令
PS D:\imgs\png> get-childitem *.png | foreach { rename-item $_ $_.name.replace( "PE ","PE-")}
但我收到此错误
ForEach-Object : Cannot bind parameter 'RemainingScripts'. Cannot convert the "" value of type "System.String" to type "System.Management.Automation.ScriptBlock".
At line:1 char:78
+ ... item *.png | foreach { rename-item $_ $_.name.replace( "PE ","PE-")}
+ ~
+ CategoryInfo : InvalidArgument: (:) [ForEach-Object], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.ForEachObjectCommand
答案 0 :(得分:2)
右花括号}
后有一个“零宽度无间断空格”字符(0xFEFF)
答案 1 :(得分:1)
我建议:
Rename-Item
直接接受管道输入-NewName
来阐明方法。Get-ChiltItem "*PE *" | Rename-Item -NewName {$_.Name.Replace('PE ','PE-')} -WhatIf