Powershell 不支持输出文件路径格式

Powershell 不支持输出文件路径格式,powershell,Powershell,我抓取一个文件的最后一行,并将其输出到另一个文件中,该文件的名称相同,前缀为“t”,但出现错误 $path = 'D:\files\' $inc = @("*txt_*") $exc = @("*csv_*") $List = Get-ChildItem -Path $path -recurse -include $inc -exclude $exc foreach ($item in $List) { Get-Content $item.Fullname -Tail 1 | Ou

我抓取一个文件的最后一行,并将其输出到另一个文件中,该文件的名称相同,前缀为“t”,但出现错误

$path   = 'D:\files\'
$inc = @("*txt_*")
$exc = @("*csv_*")
$List = Get-ChildItem -Path $path -recurse -include $inc -exclude $exc

foreach ($item in $List) {
    Get-Content $item.Fullname -Tail 1 | Out-File -Encoding Ascii $path"t-"$item
}

但是,如果我不在文件名前加前缀,它就可以正常工作

Get-Content $item.Fullname -Tail 1 | Out-File -Encoding Ascii $path"t-"

这有什么问题?

在文件名前面加上
T-
,然后根据文件夹名和修改后的文件名生成目标路径:

Get-ChildItem -Path $path -Recurse -Include $inc -Exclude $exc | ForEach-Object {
  $dst = Join-Path $_.Directory.FullName ($_.Name -replace '^', 'T-')
  Get-Content $_.FullName -Tail 1 | Set-Content $dst -Encoding ascii
}

在我们的
foreach
循环中添加此命令:
Write Host$path“t-”$item
。您认为打印的值是否为有效文件名?
“$($path)t-$($item.name)”
$项是对象而不是字符串。你想在那里看到哪一部分。。。只是名称?我想输出相同的文件名,并在Front中加上前缀“T-”。我正在将每个文件的最后一行提取到另一个文件,我需要两个文件都存在。