我有几次在不合时宜的时候遇到过这个问题:
尝试在具有深度路径的开源Java项目上工作 在源代码控制中存储深度fitness wiki树 试图使用Bazaar导入源代码控制树时出错
为什么会有这个限制?
为什么它还没有被移除?
您如何应对路径限制? 不,切换到Linux或Mac OS X并不是这个问题的有效答案;)
我有几次在不合时宜的时候遇到过这个问题:
尝试在具有深度路径的开源Java项目上工作 在源代码控制中存储深度fitness wiki树 试图使用Bazaar导入源代码控制树时出错
为什么会有这个限制?
为什么它还没有被移除?
您如何应对路径限制? 不,切换到Linux或Mac OS X并不是这个问题的有效答案;)
当前回答
您可以将文件夹作为驱动器挂载。从命令行,如果你有一个路径C:\path\to\long\文件夹,你可以将它映射到驱动器号X:使用:
subst x: \path\to\long\folder
其他回答
这并不是严格意义上的,因为NTFS文件系统支持最多32k个字符的路径。你可以使用win32 api和“\\?”使用大于260个字符作为路径前缀。
. net BCL团队博客中关于漫长路径的详细解释。 一个小节选强调了长路径的问题
Another concern is inconsistent behavior that would result by exposing long path support. Long paths with the \\?\ prefix can be used in most of the file-related Windows APIs, but not all Windows APIs. For example, LoadLibrary, which maps a module into the address of the calling process, fails if the file name is longer than MAX_PATH. So this means MoveFile will let you move a DLL to a location such that its path is longer than 260 characters, but when you try to load the DLL, it would fail. There are similar examples throughout the Windows APIs; some workarounds exist, but they are on a case-by-case basis.
您可以将文件夹作为驱动器挂载。从命令行,如果你有一个路径C:\path\to\long\文件夹,你可以将它映射到驱动器号X:使用:
subst x: \path\to\long\folder
至于为什么这个问题仍然存在——微软并不认为它是一个优先级,并且认为向后兼容性比改进他们的操作系统更重要(至少在这种情况下)。
我使用的一种变通方法是为路径中的目录使用“短名称”,而不是使用标准的、人类可读的版本。例如,对于C:\Program Files\,我会使用C:\PROGRA~1\你可以使用dir /x找到简短的等价名称。
另一种处理方法是使用Cygwin,这取决于您想对文件做什么(即Cygwin命令是否适合您的需要)
例如,它允许复制、移动或重命名连Windows资源管理器都做不到的文件。当然,也可以处理它们的内容,如md5sum、grep、gzip等。
此外,对于你正在编写的程序,你可以将它们链接到Cygwin DLL,这将使它们能够使用长路径(我还没有测试这个)
从Windows 10。可以通过修改注册表项来消除限制。
Tip Starting in Windows 10, version 1607, MAX_PATH limitations have been removed from common Win32 file and directory functions. However, you must opt-in to the new behavior. A registry key allows you to enable or disable the new long path behavior. To enable long path behavior set the registry key at HKLM\SYSTEM\CurrentControlSet\Control\FileSystem LongPathsEnabled (Type: REG_DWORD). The key's value will be cached by the system (per process) after the first call to an affected Win32 file or directory function (list follows). The registry key will not be reloaded during the lifetime of the process. In order for all apps on the system to recognize the value of the key, a reboot might be required because some processes may have started before the key was set. The registry key can also be controlled via Group Policy at Computer Configuration > Administrative Templates > System > Filesystem > Enable NTFS long paths. You can also enable the new long path behavior per app via the manifest: <application xmlns="urn:schemas-microsoft-com:asm.v3"> <windowsSettings xmlns:ws2="http://schemas.microsoft.com/SMI/2016/WindowsSettings"> <ws2:longPathAware>true</ws2:longPathAware> </windowsSettings> </application>