http://delphi.about.com/bltip1199.htm
http://delphi.ktop.com.tw/TOPIC.ASP?TOPIC_ID=21922
代碼: 選擇全部
uses ShellAPI;
Function DelTree(DirName : string): Boolean;
{
Completely deletes a directory regardless
of whether the directory is filled or has
subdirectories. No confirmation is requested
so be careful. If the operation is successful
then True is returned, False otherwise
}
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;
//
//
//
//
//
//
{
//使用方式
if DelTree('c:TempDir') then
ShowMessage('Directory deleted!')
else
ShowMessage('Errors occured!');
}