Delete Folder in Delphi.
Maybe there is another and more convenient way in Delphi to delete a folder, but what I could find and integrate into my application is the following function:
function DelDirTree(dirName : string): boolean;
var
SHFileOpStruct : TSHFileOpStruct;
dirBuf : array [0..255] of char;
begin
try
Fillchar(SHFileOpStruct,Sizeof(SHFileOpStruct),0) ;
FillChar(dirBuf, Sizeof(dirBuf), 0 ) ;
StrPCopy(dirBuf, dirName) ;
with SHFileOpStruct do begin
Wnd := 0;
pFrom := @dirBuf;
wFunc := FO_DELETE;
fFlags := FOF_ALLOWUNDO;
fFlags := fFlags or FOF_NOCONFIRMATION;
fFlags := fFlags or FOF_SILENT;
end;
Result := (SHFileOperation(SHFileOpStruct) = 0) ;
except
Result := false;
end;
end;
