delphi 删除整个目录


本文整理自网络,侵删。

 
function DeleteDirectory(NowPath: string): Boolean; // 删除整个目录
var
  f : TSearchRec;
  ret: integer;
  key: string;

begin
  if not DeleteTree(NowPath) then
  begin
      if NowPath[Length(NowPath)] <> '\' then
        NowPath := NowPath + '\';
      key := NowPath + '*.*';
      
      ret := FindFirst(key, faAnyFile, f);
      while ret = 0 do
      begin
        if ((f.Attr and fadirectory) = fadirectory) then
        begin
          if (f.Name <> '.') and (f.name <> '..') then
            DeleteDirectory(NowPath + f.name);
        end
        else
        begin
          if ((f.Attr and fadirectory) <> fadirectory) then
          begin
            deletefile(NowPath + f.name);
          end;
        end;
        ret := FindNext(f);
      end;
      findClose(f);

      removedir(NowPath);// 如果需要删除文件夹则添加
      result := True;
  end;
end;

相关阅读 >>

Delphi 安卓如何获取当前系统语言

Delphi内嵌汇编语言basm精要

Delphi idpop3收邮件

Delphi tstringlist的用法

Delphi 回车符 换行符

Delphi程序版本信息设置说明

Delphi tstopwatch 计时

Delphi ip地址转换str字符

Delphi 判断一个数组的长度用 length 还是 sizeof ?

Delphi 获取dll文件的函数列表

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



打赏

取消

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

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

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

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

评论

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