SmartPascal
ForceDirectories
Function
Create a new path of directories SysUtils unit
 function ForceDirectories ( const Path : string ) : Boolean;
Description
The ForceDirectories function creates one or more nested directories specified by the Path.
 
If the create succeeded, then True is returned, otherwise the error can be obtained using GetLastError.
Related commands
CreateDir Create a directory
GetCurrentDir Get the current directory (drive plus directory)
GetDir Get the default directory (drive plus path) for a specified drive
MkDir Make a directory
ChDir Change the working drive plus path for a specified drive
RmDir Remove a directory
RemoveDir Remove a directory
SelectDirectory Display a dialog to allow user selection of a directory
SetCurrentDir Change the current directory
 
Example code : Create a new path on the C drive
// Full Unit code.
// -----------------------------------------------------------
// You must store this code in a unit called Unit1 with a form
// called Form1 that has an OnCreate event called FormCreate.
 
unit Unit1;
 
interface
 
uses
  SysUtils,   // Unit containing the ForceDirectories command
  Forms, Dialogs;
 
type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  end;
 
var
  
Form1: TForm1;
 
implementation
{$R *.dfm} // Include form definitions
 
procedure TForm1.FormCreate(Sender: TObject);

begin
  // Try to create a new nested directory in the current directory
  if CreateDir('C:\NonExistantDir\TestDir')
  then ShowMessage('New directory added OK')
  else ShowMessage('New directory add failed with error : '+
                   IntToStr(GetLastError));

  // Now force it to create this directory
  if ForceDirectories('C:\NonExistantDir\TestDir')
  then ShowMessage('New directory added OK')
  else ShowMessage('New directory add failed with error : '+
                   IntToStr(GetLastError));
end;
 
end.
Hide full unit code
   New directory add failed with error 3
   New directory added OK