简体   繁体   English

如何在 Delphi 中递归创建文件夹?

[英]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. Delphi 函数 MkDir 返回 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.) (这是一个标准的 RTL 函数,可以在 SysUtils.pas 中找到。因此您不需要创建自己的函数,即使这并不困难。)

This uses the new IOUtils instead of SysUtils.这将使用新的 IOUtils 而不是 SysUtils。
IOUtils is cross-platform compatible and UNC aware (but is also buggy in a few places). IOUtils 是跨平台兼容和 UNC 感知的(但在一些地方也有问题)。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM