delphi删除整个目录及目录下的文件


本文整理自网络,侵删。

 
//删除整个文件夹及其下的所有文件
function DelDirAll(aDir: string): Boolean;
var
vSearch: TSearchRec;
vRet: integer;
vKey: string;
begin

if aDir[Length(aDir)] <> '\' then
aDir := aDir + '\';
vKey := aDir + '*.*';
vRet := FindFirst(vKey, faanyfile, vSearch);
while vRet = 0 do
begin
if ((vSearch.Attr and fadirectory) = fadirectory) then
begin
if (vSearch.Name <> '.') and (vSearch.name <> '..') then
DelDirAll(aDir + vSearch.name);
end
else
begin
if ((vSearch.Attr and fadirectory) <> fadirectory) then
begin
{System.Sysutils.}DeleteFile(aDir + vSearch.name);
end;
end;
vRet := FindNext(vSearch);
end; //while

{System.SysUtils.}FindClose(vSearch);
Removedir(aDir); // 如果需要删除文件夹则添加
result := True;
end;

相关阅读 >>

Delphi selectdirectory 选择文件夹

Delphi 判断文件名是否合法,判断文件名路径是否合法

Delphi 模糊查询和字段查询

Delphi写一个utf8编码格式的文本文件

Delphi 对非活动窗口进行屏幕截图

Delphi getrandompassword 生成随机密码

Delphi listview 实现进度条显示

Delphi android 获取通�记录

Delphi 如何检测你的电脑日期或时间的变化

Delphi中使用flash控件

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



打赏

取消

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

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

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

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

评论

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