频道分类

delphi 删除整个目录

作者:admin 来源: 日期:2020/3/5 22:06:46 人气: 标签:

 
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 计算加班时间工时的函数下一篇:没有资料