开发者

How can I Create folders recursively in Delphi?

Need some help in creating function which can create folders recursively with giving开发者_运维技巧 path:

C:\TestFolder\Another\AndAnother

Delphi function MkDir returning IOerror = 3.

MkDir('C:\TestFolder\Another\AndAnother');


Use

ForceDirectories('C:\TestFolder\Another\AndAnother');

(This is a standard RTL function, found in SysUtils.pas. Hence you do not need to create your own function, even though that wouldn't have been difficult.)


SysUtils is obsolete now and ForceDirectories is not UNC aware!

There is a new library in since Delphi XE7 (or even earlyer?) called IOUtils.
IOUtils is cross-platform compatible and UNC aware.

function ForceDirectories(FullPath: string): Boolean;   // Works with UNC paths
begin
  TDirectory.CreateDirectory(FullPath);
  Result:= DirectoryExists(FullPath);
end;

Note: The function is from Delphi LightSaber library. There are several other similar I/O functions there (like ListFilesOf(Folder)).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜