本文整理自网络,侵删。
delphi删除目录及子目录及所有目录下的文件
uses shellapi;
Function DelTree(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;
procedure TForm1.Button4Click(Sender: TObject);
begin
if DelTree('c:\abc') then
ShowMessage('Directory deleted!')
else
ShowMessage('Errors occured!');
end;
相关阅读 >>
Delphi twebbrowser出现 method pastehtml not supported by automation object 解决方法
Delphi之tclientsocket和tserversocket使用tcp keepalive心跳机制实现“断网”、"断电"检测
monthoftheyear:取得一个tdatetime变量的月份在年度中的索引
更多相关阅读请进入《Delphi》频道 >>