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 隐藏进程代码

Delphi限制edit编辑框的输入

Delphi建立文件的快捷方式

Delphi 解析json生成json

Delphi的tclientsocket组件和tserversocket组件(c/s)说明

Delphi idhttp下载文件

Delphi 如何在在windows平台下实现进程隐藏

Delphi 2009 之 tstringbuilder 类[7]: tostring

Delphi edit只能输入数字或小数点

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



打赏

取消

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

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

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

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

评论

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