How can I Create folders recursively in Delphi?

Andrew Rumm picture Andrew Rumm · Jul 12, 2010 · Viewed 7.2k times · Source

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');

Answer

Andreas Rejbrand picture Andreas Rejbrand · Jul 12, 2010

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