function DeleteDirectory(mSource: string): Boolean;
var
vSHFileOpStruct: TSHFileOpStruct;
begin
FillChar(vSHFileOpStruct, SizeOf(vSHFileOpStruct), 0);
with vSHFileOpStruct do
begin
Wnd := Application.Handle;
wFunc := FO_DELETE;
pFrom := PChar(mSource + #0);
pTo := #0#0;
fFlags := FOF_NOCONFIRMATION+FOF_SILENT;
end;
Result := SHFileOperation(vSHFileOpStruct) = 0;
end; { DeleteDirectory }
procedure TForm1.Button1Click(Sender: TObject);
begin
DeleteDirectory( 'C:\temp ');
end;
procedure DelDir(SourcePath: String);
var
sr: TSearchRec;
begin
SourcePath:=IncludeTrailingPathDelimiter(SourcePath);
if FindFirst(SourcePath + '*.* ', faAnyFile, sr) = 0 then
begin
repeat
DeleteFile(SourcePath + sr.Name);
until FindNext(sr) <> 0;
FindClose(sr);
RemoveDir(SourcePath);
end;
end;