环境是Windows 7 Pro和Delphi 7。
Windows.CreateDirectory()无法在远低于路径长度限制的非常长的路径中创建多个文件夹。 GetLastError()返回ERROR_PATH_NOT_FOUND。
ESXi 虚拟机以及本机 Win7 工作站和物理磁盘上的故障是相同的。发生类似的故障Windows.MoveFile()。
下面代码中的长路径是在 CMD 窗口中作为粘贴参数正确创建的MKDIR。
我的解决方法是零碎地创建这条长路。我将 '\' 字符处的路径拆分为一个字符串数组。然后我遍历数组并从每个元素构建累积路径。循环正确构建完整路径而不会出错。
我不知道为什么 Win32 函数无法创建有效的长路径。
var
arrDstPath : TStringArray;
begin
// --------------
// failing method
// --------------
strDstPath := 'C:\Duplicate Files\my customer recovered data\desktop\my customer name\application data\gtek\gtupdate\aupdate\channels\ch_u3\html\images\';
if (Windows.CreateDirectory(pchar(strDstPath),nil) = false) then
Result := Windows.GetLastError; // #3 is returned
if (DirectoryExists(strNewPath) = false) then
Result := ERROR_PATH_NOT_FOUND;
// -----------------
// successful method
// -----------------
strNewPath := '';
LibSplitToArray(arrDstPath,'\',strDstPath); …Run Code Online (Sandbox Code Playgroud)