【发布时间】:2018-11-16 22:51:00
【问题描述】:
我需要字符串的前 3 个字节。我的代码出错了。
# This Code don't work
$folderoutput="Z:\Home\Chronos\" + $datum.Month;
$test = Get-ChildItem -Path $folderinput| select name, state -last 1
$test.Substring(0,3)
# This Code work
$folderoutput="Z:\Home\Chronos\" + "11"
$test = Get-ChildItem -Path $folderinput| select name, state -last 1
$test.Substring(0,3)
错误:
方法调用失败,因为 [Selected.System.IO.FileInfo] 确实 不包含名为“子字符串”的方法。在 Z:\skript\uebung1.ps1:16 字符:1 + $test.Substring(0,3) + ~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (Substring:String) [], RuntimeException + FullyQualifiedErrorId : MethodNotFound
错误的原因是什么?
【问题讨论】:
标签: powershell directory substring get-childitem