Name

RmDir Procedure

Syntax

procedure RmDir(const Directory: string);

Description

RmDir removes a directory. If RmDir cannot delete the directory, it reports the Windows error code as an I/O error. In particular, if the directory is not empty, the error code is Error_Dir_Not_Empty (145). RmDir is not a real procedure.

Example

// Delete a directory and its contents.
procedure DestroyDir(const Directory: string);
var
  Path: string;
  Search: TSearchRec;
begin
  Path := IncludeTrailingBackslash(Directory);
  if FindFirst(Path + '*.*', faAnyFile, Search) = 0 then
  try
    repeat
      if (Search.Attr and faDirectory) <> 0 then
        DestroyDir(Path + Search.Name)
      else
        DeleteFile(Path + Search.Name);
    until FindNext(Search) <> 0;
  finally
    FindClose(Search);
  end;
  RmDir(Path);
end;

See Also

ChDir Procedure, GetDir Procedure, IOResult Function, MkDir Procedure

Get Delphi in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.