【发布时间】:2011-11-03 03:40:08
【问题描述】:
调用此 powershell 命令并收到错误。快把我逼疯了。
Prompt> get-childitem -recurse ./ *NYCSCA* | where-object { $_.Name -like
"*NYCSCA*" } | rename-item $_ -newname $_.Name.Replace(" ","_") -whatif
下面是回复:
You cannot call a method on a null-valued expression.
At line:1 char:140
+ get-childitem -recurse ./ *NYCSCA* | where-object { $_.Name -like "*NYCSCA*" } | select FullName | rename-item $_ -n
ewname $_.Name.Replace <<<< (" ","_") -whatif
+ CategoryInfo : InvalidOperation: (Replace:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
如果我删除最后一部分,我会得到一个文件列表。有什么线索吗?很明显,我还没有熟悉 powershell。
注意:我试图将其发布给超级用户,但该网站现在一直失败 - 不允许我添加这个确切的问题。
这里大大简化了。我什至无法让这个经典示例起作用。
gci *NYCSCA* | ren $_ ($_.Name).Replace("foo","bar")
谢谢@JNK,% 做到了。如果您有兴趣,我需要的解决方案是:
gci -recurse | where-object{ $_.Name -like "*NYCSCA*"} | %{rename-item $_.FullName $_.FullName.Replace("NYCSCA","SDUSD") }
【问题讨论】:
标签: powershell