delphi删除目录及子目录及所有目录下的文件


本文整理自网络,侵删。

 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 一个定时器timer1相关的简单例子

Delphi 根据年份获取年干支

Delphi 自动关闭弹出的窗口

Delphi使用indy组件http上传文件

idhttp使用时内存猛增,如何解决

Delphi twebbrowser出现 method pastehtml not supported by automation object 解决方法

Delphi 让"显示桌面"功能对你的窗口无效

Delphi之tclientsocket和tserversocket使用tcp keepalive心跳机制实现“断网”、"断电"检测

Delphi 遍历系统窗口标题可用于反外挂反破解

monthoftheyear:取得一个tdatetime变量的月份在年度中的索引

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...