ForceDirectories 返回 False
我正在使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将路径分隔符更改为适合您的平台(Win32)的路径分隔符,一切都会好起来:
为了使代码跨平台可移植(为将来可能与您的 Delphi 代码相关的时间做准备),您可以:
这可以改进重用(仅搜索/替换不= PathDelim 的符号),但演示了原理。
Change your path delimiter to that which is correct for your platform (Win32) and all will be good:
To make the code portable across platforms (in preparation for some future time when this may be relevant to your Delphi code) you could:
This could be improved for re-use (only search/replace the symbol which is no = PathDelim) but demonstrates the principle.
显然
ForceDirectories
只喜欢\
的,而不喜欢/
的......愚蠢的问题解决了。Apparently
ForceDirectories
only likes\
's, not/
's... Stupid problem solved.