0
我試圖弄清楚如何保持變量$Error
不受System.IO.PathTooLongException
例外的影響,但仍然在ArrayList
中收集這些長路徑供以後使用。
實施例:
$LongPath1 = "\\domain.net\bnl\Other stuff\DEPARTMENTS\SITE\Administration\Plant\Securite\Bien etre\Bien etre\Bien-être au travail\Travaux de fin d'année\Other-Stuff"
$LongPath2 = "\\domain.net\bnl\Other stuff\DEPARTMENTS\SITE\Administration\Plant\Laboratoire\Sauvegarde PC\Bibliothèques\Documents\Sauvegarde dossier Labo\Laboratoire (sauvegarde 03-2014)\Laboratoire\Travaux en cours"
Get-ChildItem -Recurse -LiteralPath $LongPath1 -ErrorVariable e -ErrorAction SilentlyContinue
Get-ChildItem -Recurse -LiteralPath $LongPath2 -ErrorVariable +e -ErrorAction SilentlyContinue
$PathTooLong = New-Object System.Collections.ArrayList($null)
$e | where {$_.Exception -like 'System.IO.PathTooLongException*'} | ForEach {
$PathTooLong.Add($_.TargetObject) | Out-Null
}
$PathTooLong
它是如何能夠刪除存儲在ErrorVariable
的「e」的長路徑從自動生成$Error
變量完全相同的錯誤?
嘗試:
Get-ChildItem -Recurse -LiteralPath $LongPath1 -ErrorVariable e -ErrorAction Ignore
我認爲將是天才之處在於使用的選項Ignore
所以$Error
變量不被自動填寫,但隨後ErrorVariable
「E」保持空.. 。
謝謝你的幫助。