Task

Create a directory and any missing parents.

This task is named after the posix mkdir -p command, and several libraries which implement the same behavior.

Please implement a function of a single path string (for example ./path/to/dir) which has the above side-effect.
If the directory already exists, return successfully.
Ideally implementations will work equally well cross-platform (on windows, linux, and OS X).

It's likely that your language implements such a function as part of its standard library. If so, please also show how such a function would be implemented.




 
program Make_directory_path;
 
{$APPTYPE CONSOLE}
 
uses
  System.SysUtils,
  System.IOUtils;
 
const
  Path1 = '.\folder1\folder2\folder3'; // windows relative path (others OS formats are acepted)
  Path2 = 'folder4\folder5\folder6';
 
begin
  // "ForceDirectories" work with relative path if start with "./"
  if ForceDirectories(Path1) then
    Writeln('Created "', path1, '" sucessfull.');
 
  // "TDirectory.CreateDirectory" work with any path format
  //  but don't return sucess, requere "TDirectory.Exists" to check
  TDirectory.CreateDirectory(Path2);
  if TDirectory.Exists(Path2) then
    Writeln('Created "', path2, '" sucessfull.');
  Readln;
end.