如果我有一个示例函数......
function foo()
{
# get a list of files matched pattern and timestamp
$fs = Get-Item -Path "C:\Temp\*.txt"
| Where-Object {$_.lastwritetime -gt "11/01/2009"}
if ( $fs -ne $null ) # $fs may be empty, check it first
{
foreach ($o in $fs)
{
# new bak file
$fBack = "C:\Temp\test\" + $o.Name + ".bak"
# Exception here Get-Item! See following msg
# Exception thrown only Get-Item cannot find any files this time.
# If there is any matched file there, it is OK
$fs1 = Get-Item -Path $fBack
....
}
}
}
异常消息是...The WriteObject and WriteError methods cannot be called after the pipeline has been closed. Please contact Microsoft Support Services.
基本上,我不能Get-Item
在函数或循环中再次使用来获取不同文件夹中的文件列表。
任何解释以及修复它的正确方法是什么?
顺便说一句,我使用的是 PS 1.0。