DELPHI中怎么判断一个文件夹是否为空


本文整理自网络,侵删。

 
function TForm1.IsDirEmpty(const ADir: String): Boolean;
var
  sPath,s: String;
  sr: TsearchRec;
  b: Boolean;
begin
  Result := True;
  s := '';
  if Copy(ADir,Length(ADir) - 1,1) <> '\' then s := '\';
  sPath := ADir + s + '*.*';
  if FindFirst(sPath,faAnyFile, sr) = 0 then
    repeat
      b := (sr.Name <> '.') and (sr.Name <> '..');
      if b then Break;
    until FindNext(sr) <> 0;
    Result := not b;
  FindClose(sr);
end;

function IsEmptyDir(sDir: String): Boolean;
var
  sr: TsearchRec;
begin
  Result := True;
  if Copy(sDir, Length(sDir) - 1, 1) <> '\' then sDir := sDir + '\';
  if FindFirst(sDir + '*.*', faAnyFile, sr) = 0 then
    repeat
      if (sr.Name <> '.') and (sr.Name <> '..'then
      begin
        Result := False;
        break;
      end;
    until FindNext(sr) <> 0;
  FindClose(sr);
end;

function IsEmpty(path: String): Boolean;
var
  f: TSearchRec;
  hasNext: Boolean;
begin
  Result := True;
  path := IncludeTrailingPathDelimiter(path);
  hasNext := FindFirst(path + '*.*', faAnyFile, f) = 0;
  while hasNext do
  begin
    if (f.Name <> '.') and (f.Name <> '..') then
    begin
      Result := False;
      Break;
    end;
    hasNext := FindNext(f) = 0;
  end;
  FindClose(f);
end;

相关阅读 >>

Delphi 进程保护

Delphi android.os获取sn号

Delphi与进程、窗口句柄、文件属性、程序运行状态

Delphi 之 tmemo组件使用

Delphi 跳出for循环

Delphi fdquery遍历输出 json

Delphi html转义

Delphi 比较两个日期是否大于n天

Delphi判断电脑是否安装了excel

Delphi 全局变量 hinstance 到底是在什么时候赋值的?

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



打赏

取消

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

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

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

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

评论

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

    正在狠努力加载,请稍候...