【问题标题】:Get-childitem when path is over 260 characters路径超过 260 个字符时获取子项
【发布时间】:2015-08-04 19:09:01
【问题描述】:

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

【问题讨论】:

  • 不,不是。基本上,.NET can't break the 260 character limit 因为它是基于 Win32 构建的,而 Win32 在支持突破 260 个字符限制方面非常糟糕,因为 30 年前 MS 承诺它的路径永远不会超过 260 个字符。您可以通过 Google 搜索找到大量的破解方法来绕过它,但其中很多都没有用,因为您不能在另一个 cmdlet 中使用长路径。

标签: powershell


【解决方案1】:

按照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")

【讨论】:

    猜你喜欢
    • 2018-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-11
    • 1970-01-01
    • 1970-01-01
    • 2021-12-19
    • 1970-01-01
    相关资源
    最近更新 更多