gpt4 book ai didi

delphi - TDirectory.GetDirectoryRoot 无法正确处理 Max_Path 字符的路径

转载 作者:行者123 更新时间:2023-12-02 06:16:25 31 4
gpt4 key购买 nike

当“Folder”长度为 259 个字符时,IOUtils.TDirectory.GetDirectoryRoot(Folder) 会出现错误(是的,它在末尾包含\分隔符):

Project Tester.exe raised exception class EPathTooLongException with message 'The specified path is too long'.

我认为我可以在路径中使用最多 260 个字符。
enter image description here

为什么 GetDirectoryRoot 不接受 Max_Path 字符的路径?

最佳答案

这就是原因:

class procedure TDirectory.InternalCheckDirPathParam(const Path: string; const ExistsCheck: Boolean);
begin
TPath.CheckPathLength(Path, MAX_PATH {$IFDEF MSWINDOWS}- TFile.FCMinFileNameLen{$ENDIF});
...
end;

这是这个“奇妙”功能的用户手册:

Returns the root directory for a given path.

Use GetDirectoryRoot to obtain the root directory for a given path. Relative paths are considered relative to the application working directory. The following table lists the parameters expected by this method.

Note: GetDirectoryRoot raises an exception if the given path is invalid or the directory does not exist.

感谢 Embarcadeor/Idera 所做的高质量工作!

<小时/>

因此,IOutils 不能与 Max_Path 结合使用。它到处都使用 InternalCheckDirPathParam!

解决方案是定义您自己的 MaxPath 常量:

  {$IFDEF MSWINDOWS}
MAXPATH= MAX_PATH- 12; { TFile.FCMinFileNameLen = 12. There is a problem in IOUtils and we cannot user Max_Path. }
{$ELSE}
MAXPATH= MAX_PATH;
{$ENDIF}

所以,现在执行 Ctrl+Shift+F 并检查所有代码:)

无论如何,冲突仍然存在:某些 API 调用返回的有效路径(260 个字符)无法传递给仅接受 248 个字符的 IOUtils。如果您找到更好的解决方案,请告诉我/我们,我会接受您的答案:)

关于delphi - TDirectory.GetDirectoryRoot 无法正确处理 Max_Path 字符的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44141996/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com