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 版 lz前辈的openprocess

Delphi延时4种方法

检测系统信息的单元 computerinfo.pas

Delphi 检测进程是否存在

Delphi 用wininet 单元实现 post提交数据

Delphi sysutils.trim、sysutils.trimleft、sysutils.trimright - 删除空格

Delphi 图像处理 二值化

Delphi 计算文件与当前时间差(天小时分钟秒)

Delphi crc算法的实现

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



打赏

取消

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

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

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

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

评论

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