ForceDirectories 返回 False

发布于 2024-10-19 05:06:21 字数 433 浏览 6 评论 0原文

我正在使用 ForceDirectories 函数,如下所示:

ForceDirectories('C:/Path/To/Dir');

它返回 False 并且根本不创建任何目录。 GetLastError 返回 0。我正在使用管理权限运行该程序。

如果我这样做,

ForceDirectories('C:/Path');
ForceDirectories('C:/Path/To');
ForceDirectories('C:/Path/To/Dir');

每个调用都会成功并创建目录。但是,这会导致 ForceDirectories 函数失去作用。有谁知道为什么它会这样? (我看着你,大卫)

I am using the ForceDirectories function like this:

ForceDirectories('C:/Path/To/Dir');

And it returns False and no directories at all are created. GetLastError returns 0. I am running the program with Administrative rights.

If I do

ForceDirectories('C:/Path');
ForceDirectories('C:/Path/To');
ForceDirectories('C:/Path/To/Dir');

Each call succeeds and the directories are created. However, this voids the usefulness of the ForceDirectories function. Does anyone know why it behaves this way? (I'm looking at you David)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

软糯酥胸 2024-10-26 05:06:21

将路径分隔符更改为适合您的平台(Win32)的路径分隔符,一切都会好起来:

  ForceDirectories('c:\Path\To\Dir');

为了使代码跨平台可移植(为将来可能与您的 Delphi 代码相关的时间做准备),您可以:

  s := 'c:/Path/To/Dir';  // << example

  s := StringReplace(s, '/', PathDelim, [rfReplaceAll]);
  s := StringReplace(s, '\', PathDelim, [rfReplaceAll]);
  ForceDirectories(s);

这可以改进重用(仅搜索/替换不= PathDelim 的符号),但演示了原理。

Change your path delimiter to that which is correct for your platform (Win32) and all will be good:

  ForceDirectories('c:\Path\To\Dir');

To make the code portable across platforms (in preparation for some future time when this may be relevant to your Delphi code) you could:

  s := 'c:/Path/To/Dir';  // << example

  s := StringReplace(s, '/', PathDelim, [rfReplaceAll]);
  s := StringReplace(s, '\', PathDelim, [rfReplaceAll]);
  ForceDirectories(s);

This could be improved for re-use (only search/replace the symbol which is no = PathDelim) but demonstrates the principle.

独孤求败 2024-10-26 05:06:21

显然 ForceDirectories 只喜欢 \ 的,而不喜欢 / 的......愚蠢的问题解决了。

Apparently ForceDirectories only likes \'s, not /'s... Stupid problem solved.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文