RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
SysUtils.CreateDir Function

Creates a new directory.

Pascal
function CreateDir(const Dir: string): Boolean;
C++
Boolean CreateDir(const AnsiString Dir);

SysUtils

CreateDir creates a new directory. The return value is true if a new directory was successfully created, or false if an error occurred.  

C++ Examples: 

 

/*
The following example creates a directory ‘C:\temp’ if it
does not already exist.
}
*/
#include <Filectrl.hpp>
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  if (!DirectoryExists("c:\\temp"))
  {
    if (!CreateDir("C:\\temp"))
      throw Exception("Cannot create c:\\temp directory.");
  }
  if (!CreateDir("C:\\temp"))
    throw Exception("The c:\\temp directory already exists.");
}

 

Delphi Examples: 

{
The following example creates a directory ‘C:\temp’ if it
does not already exist.
}
uses FileCtrl;
procedure TForm1.Button1Click(Sender: TObject);
begin
  if not SysUtils.DirectoryExists('C:\temp') then
    if not CreateDir('C:\temp') then
      raise Exception.Create('Cannot create C:\temp');
  if not CreateDir('C:\temp') then
    raise Exception.Create('Cannot create C:\temp again!');
end;

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!