路径超过260个字符时的Get-childitem

时间:2015-08-04 19:09:02

标签: powershell

我有这个powershell: Get-ChildItem -Path $FileSource | ? {$_.psIsContainer -eq $False}Get-ChildItem -Path $FileSource | ? {$_.psIsContainer -eq $True} 然后我在一个数组中使用它来遍历文件和文件夹。当fileshare超过260个字符时,这会导致错误。反正有没有做同样的事情,但没有得到错误?

1 个答案:

答案 0 :(得分:0)

根据How to avoid System.IO.PathTooLongException?的建议,您可以使用第三方图书馆,例如Delimon.Win32.I O.

示例代码:

Add-Type -Path "D:\temp\Delimon.Win32.IO.dll"
[Delimon.Win32.IO.Directory]::GetFiles("\\longpath")
[Delimon.Win32.IO.Directory]::GetDirectories("\\longpath")
相关问题