我在这两种情况下有不同的结果:
- 案例1:
Get-ChildItem -Path "\\?\UNC\very\long\path"
- 案例二:
Get-ChildItem -Path "\\very\long\path"
如果长路径的长度小于260个字符,我会得到不同的结果。
- case 1:返回零个子项。
- 情况2:所有子项都是预期的。
为了得到相同的结果,我应该在情况1中做不同的事情:
Get-ChildItem -Path "\\?\UNC\very\long\path\*"
字符串
为什么会有这种差异?我使用\\?\UNC
前缀,因为完整路径是可变的,我不知道它。
也许我应该在这两种情况下使用\*
通配符?
1条答案
按热度按时间nhaq1z211#
您在 Windows PowerShell 中看到**一个 bug,当您使用长路径前缀(本地路径为
\\?\
,UNC路径为\\?\Unc\
)将 literal 路径(非通配符)传递到(可能是位置暗示的)-Path
参数时,该bug会出现。详情见底部。要解决这个问题,使用
-LiteralPath
参数,这对非wildcard路径来说是正确的:字符串
注意事项:
Windows PowerShell bug详情:
当您将具有长路径前缀的非通配符 * 根 * 路径传递给
-Path
时,该错误就会出现,这适用于使用本地和UNC形式的前缀,尽管症状不同:型
型
然而,奇怪的是,local 形式在驱动器 root 级别上不支持 * 通配符 *:
型
顺便说一句:
*
来发现给定服务器上的可用共享;像Get-ChildItem -Path \\server1\*
或Get-ChildItem -Path \\?UNC\server1\*
这样的东西永远不会产生输出。