嘿傢伙我剛剛開始與PowerShell,現在我有這個問題。我試圖檢查輸入路徑的最後一個字符是否是「\」。但是當我運行這個代碼時,變量$ lastRootPathChar是空的。 $ end和$ start變量獲得我希望它們具有的整數,但.Substring似乎不會返回任何結果。我究竟做錯了什麼?沒有來自Substring的結果
$RootPath = Read-Host 'Please enter the rootpath: '
$start = $RootPath.Length-1
$end = $RootPath.Length
$lastRootPathChar = $RootPath.Substring($start,$end)
if($lastRootPathChar -ne "\")
{
$RootPath = $RootPath + "\"
}
請將*代碼*粘貼到代碼 –
的問題中,而不是*屏幕截圖*以便將來參考,將代碼粘貼到問題中,而不是代碼的屏幕截圖! – Jamiec