我有一個腳本,它能夠準確地告訴我目錄中有多少個文件夾以及其中的子目錄。但是,對於我正在使用的一個目錄,有一些快捷方式文件夾似乎會導致腳本失敗。計算目錄中的文件夾數量並忽略快捷方式
下面是我收到錯誤消息:
Get-ChildItem : Could not find a part of the path 'C:\Folder\SubFolder\folder1\jpos'.
At C:\Desktop\Script Files\fileCount.ps1:34 char:10
+ $items = Get-ChildItem C:\Folder\SubFolder\ -Recurse
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ReadError: (C:\Folder\SubFolder\folder1\jpos:String) [Get-ChildItem],
DirectoryNotFoundException
+ FullyQualifiedErrorId :
DirIOError,Microsoft.PowerShell.Commands.GetChildItemCommand`
運行該腳本罰款沒有快捷方式的目錄,但它似乎時有目錄中的快捷方式總是失敗。
下面是本節的代碼片段:
$items = Get-ChildItem C:\Folder\SubFolder -Recurse
$termFolder = ($items | Where-Object {$_.PSIsContainer}).count
有沒有辦法跳過快捷方式或一個更好的方式做一個文件夾算不算?
當你說的快捷鍵你的意思鏈接? [這可能是一個騙局](https://stackoverflow.com/questions/29763790/how-to-make-get-childitem-not-to-follow-links)。看看那裏鏈接的超級用戶問題 – Matt
GCI有一個'-Directory'開關。 – TheIncorrigible1
@ TheIncorrigible1不在早期的PS版本。 '{PSIsContainer}'的服務地點相同。 – LotPings