首页 > 解决方案 > “找不到路径的一部分”是什么意思?

问题描述

get-childitemselect-string可以处理的路径的大小是否有限制?如果是,有什么替代方案?

当我在路径上运行以下命令时:

PS E:\KINGSTON backup5\03 Learning\Softwares\Mathematica\Mathematica 12\Mathematica Directories Backup2\C,Users,atfai,AppData,Roaming,Mathematica\Paclets\Repository\SystemDocsUpdate1-12.0.0\Documentation\English\Workflows> get-childitem -recurse -filter "*.nb" -file | select-string -pattern ".*ProcessObject.*" -casesensitive

我收到以下错误

选择字符串:文件 E:\KINGSTON backup5\03 Learning\Softwares\Mathematica\Mathematica 12\Mathematica 目录 Backup2\C,Users,atfai,AppData,Roaming,Mathematica\Paclets\Repository\SystemDocsUpdate1-12.0.0\Documentation\ English\Workflows\ChangeTheStyleOfPointsInA2DScatterPlot.nb 无法读取:找不到路径的一部分 'E:\KINGSTON backup5\03 Learning\Softwares\Mathematica\Mathematica 12\Mathematica Directories Backup2\C,Users,atfai,AppData,Roaming, Mathematica\Paclets\Repository\SystemDocsUpdate1-12.0.0\Documentation\English\Workflows\ChangeTheStyleOfPointsInA2DScatterPlot.nb'。在 line:1 char:47 + ... nb" -file | select-string -pattern "。过程对象。" - 区分大小写 ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Select-String], ArgumentException + FullyQualifiedErrorId : ProcessingFile,Microsoft.PowerShell.Commands.SelectStringCommand

此外,如果我在以下路径上运行相同的命令:

PS E:\Computer Backup\Downloads - Current\Windows 10 Optimization\SoftwareDistribution.old3\Download\736aed4d238d4999f5ea5b04589077ed\Package_for_RollupFix~~amd64~~17134.677.1.6\x86_wcf-system.servicemodel_b03f5f7f11d50a3a_10.0.17134.254_none_d5ff175e12d127c0> get-childitem -recurse -filter "*.nb" -file | select-string -pattern ".*ProcessObject.*" -casesensitive

这次我得到了错误get-childitem

get-childitem : 找不到路径的一部分 'E:\Computer Backup\Downloads - Current\Windows 10 Optimization\SoftwareDistribution.old3\Download\736aed4d238d4999f5ea5b 04589077ed\Package_for_RollupFix~~amd64~~17134.677.1.6\x86_wcf-system。 servicemodel_b03f5f7f11d50a3a_10.0.17134.254_none_d5ff175e12d127c0'。在 line:1 char:1 + get-childitem -recurse -filter "*.nb" -file | select-string -pattern ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~ + CategoryInfo : ReadError: (E:\Computer Bac...5ff175e12d127c0:String) [Get-ChildItem], DirectoryNotFoundException + FullyQualifiedErrorId : DirIOError,Microsoft.PowerShell.Commands.GetChildItemCommand

“找不到路径的一部分”是什么意思?驱动器 E 具有 Windows 支持的 NTFS 文件系统,因此它的 powershell 命令应该能够处理它吗?这里发生了什么?

顺便说一句,我可以从 Windows 资源管理器访问这两个路径并在记事本中打开文件。所以路径存在并且文件显然没有损坏或无法访问。

标签: powershell

解决方案


问题是,您的操作系统上未启用长路径,因此限制为 260 个字符。

根据您运行的 Windows 版本,这可以通过启用组策略来解决Local Computer Policy > Computer Configuration > Administrative Templates > System > Filesystem > NTFS > Enable NTFS long paths

如果您没有该选项,则将注册表项的值更改LongPathsEnabledHKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystemfrom 0to1也可以完成这项工作。


推荐阅读