uses shellapi
function DelTree(aDir:String):Boolean;
Var
FO:TSHFileOpStruct;
P:String;
begin
result:=false;
With FO do Begin
Wnd:=0;
wFunc:=FO_DELETE;
pFrom:=Pchar(aDir);
pTo:=nil;
fFlags:=FOF_ALLOWUNDO;
hNameMappings:=nil;
lpszProgressTitle:=PChar('正在删除文件夹'+aDir);
fAnyOperationsAborted:=False;
End;
if SHFileOperation(FO)=0 then result:=true;
end;
注意 fFlags:=FOF_ALLOWUNDO;可以改成以下几种标志的+
比如如果还不要提示确认,就fFlags:=FOF_ALLOWUNDO+FOF_NOCONFIRMATION;
FOF_ALLOWUNDO Preserves undo information, if possible.
FOF_CONFIRMMOUSE Not implemented.
FOF_FILESONLY Performs the operation only on files if a wildcard filename (*.*) is specified.
FOF_MULTIDESTFILES Indicates that the pTo member specifies multiple destination files (one for each source file) rather than one directory where all source files are to be deposited.
FOF_NOCONFIRMATION Responds with "yes to all" for any dialog box that is displayed.
FOF_NOCONFIRMMKDIR Does not confirm the creation of a new directory if the operation requires one to be created.
FOF_RENAMEONCOLLISION Gives the file being operated on a new name (such as "Copy #1 of...") in a move, copy, or rename operation if a file of the target name already exists.
FOF_SILENT Does not display a progress dialog box.
FOF_SIMPLEPROGRESS Displays a progress dialog box, but does not show the filenames.
FOF_WANTMAPPINGHANDLE Fills in the hNameMappings member. The handle must be freed by using the SHFreeNameMappings function.