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 api 做的 serversocket 例子

Delphi textfile读取文本文件

Delphi2010 编译变量$region用法

Delphi实现全局鼠标钩子

Delphi memo1 行倒序排列三种方法

Delphi版多开源码,也就是遍历系统内核对象句柄

Delphi 谷歌api文本转换语音mp3文件

Delphi firemonkey应用程序中显示时隐藏虚拟键盘

Delphi crc32算法

Delphi 调用shellexecute打开txt文本

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



打赏

取消

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

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

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

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

评论

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