尝试使用 Substring() 遍历 $File 数组的 AWS PowerShell 错误

AWS PowerShell Error trying to use Substring() going through a $File array

除 Substring() 外一切正常。我想用文件名的左10个字节作为文件夹名来保存文件。

错误信息: 方法调用失败,因为 [System.IO.FileInfo] 不包含方法 名为 'Substring'.

PowerShell code:
$Filter = "*.SCNX"
$files = @(get-childitem  -path $OutBoxPath -filter $filter)
Write-Host 'File Count? ' $Files.count
foreach ($file in $files) {
Write-Host 'File ' $File
Write-Host $File.Substring(0,10)
}

使用$File.Name 属性获取文件名。 System.IO.FileInfo 是来自 .NET Framework 的 class,您可以在 docs

中阅读有关它的信息