开发者

ForceDirectories returns False

开发者 https://www.devze.com 2023-02-13 18:09 出处:网络
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 r开发者_如何学编程eturns 0. I am r

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 r开发者_如何学编程eturns 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)


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消