How can I Create folders recursively in Delphi?

后端 未结 2 1614
误落风尘
误落风尘 2021-02-12 12:41

Need some help in creating function which can create folders recursively with giving path:

C:\\TestFolder\\Another\\AndAnother

Delphi function

相关标签:
2条回答
  • 2021-02-12 13:11

    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.)

    0 讨论(0)
  • 2021-02-12 13:25

    This uses the new IOUtils instead of SysUtils.
    IOUtils is cross-platform compatible and UNC aware (but is also buggy in a few places).

    function ForceDirectories(FullPath: string): Boolean;   // Works with UNC paths
    begin
      TDirectory.CreateDirectory(FullPath);
      Result:= DirectoryExists(FullPath);
    end;
    
    0 讨论(0)
提交回复
热议问题