Remove a directory System unit
 procedure RmDir ( const DirectoryName : string ) ;
The RmDir procedure removes a directory from the current directory.
If the directory does not exist, an EInOutError exception is thrown.
You can avoid such an exception by preventing IO errors using the {$IOChecks Off} compiler directive. You must then check the IOResult value to see the outcome of your IO operation (rememering that use of IOResult resets the value).
Related commands
$IOChecks When on, an IO operation error throws an exception
ChDir Change the working drive plus path for a specified drive
CreateDir Create a directory
GetCurrentDir Get the current directory (drive plus directory)
IOResult Holds the return code of the last I/O operation
MkDir Make a directory
RemoveDir Remove a directory
SelectDirectory Display a dialog to allow user selection of a directory
SetCurrentDir Change the current directory
ForceDirectories Create a new path of directories
 Download this web site as a Windows program.

Development Boards at very low prices with free postage.

Example code : Create a directory and then remove it
// 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;
  // The System unit does not need to be defined
  Forms, Dialogs;
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
Form1: TForm1;
{$R *.dfm} // Include form definitions
procedure TForm1.FormCreate(Sender: TObject);

  error : Integer;

  // Try to create a new subdirectory in the current directory
  // Switch off I/O error checking
  {$IOChecks off}

  // Did the directory get created OK?
  error := IOResult;
  if error = 0
  then ShowMessage('Directory created OK')
  else ShowMessageFmt('Directory creation failed with error %d',[error]);

  // Delete the directory to tidy up

  // Did the directory get removed OK?
  error := IOResult;
  if error = 0
  then ShowMessage('Directory removed OK')
  else ShowMessageFmt('Directory removal failed with error %d',[error]);
Hide full unit code
   Directory created OK
   Directory removed OK
Delphi Programming Neil Moffatt 2002 - 2014. All rights reserved.  |  Contact the author  |  Home Page