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获取jpg图片的高度、宽度

Delphi 自定义colorbox只显示指定颜色项目 colorbox显示中文颜色名称

Delphi 删除cookies及上网记录

Delphi webbrowser 滚动条的去除、边框去除

Delphi access violations 问题的解决之道

Delphi发送邮件

Delphi xe安装 tclientsocket, tserversocket控件

Delphi 让控制台窗口不现实出来

Delphi 得到cxgrid筛选后的记录数

Delphi 简单方法搜索定位treeview项

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



打赏

取消

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

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

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

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

评论

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