RmDir Procedure
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.
// 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;