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 xe android 程序切换到后台及从后台切换到前台实现

Delphi setcurrentdir 设置当前文件夹路径

Delphi10.3 创建一条json数据

Delphi 实现php的urlencode编码效果

Delphi2010中Delphi class explorer妙用

Delphi 测试字符串写入类: tstringwriter

Delphi 检测文件是否被占用

Delphi 能否把.txt文件的数据导入到access数据库中

Delphi shellexecute打开文件另类用法

Delphi hexstrtostream

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



打赏

取消

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

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

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

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

评论

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