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中frame和form有何区别

Delphi比较两个位图是否相同

Delphi windowsapi: muldiv

Delphi 获取标题栏高

Delphi的combobox不能输入只能选择

Delphi hex --> string

Delphi 手机号码库段号地区查询

Delphi console程序中一种定时方法

Delphi tclientdataset用法详解

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



打赏

取消

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

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

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

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

评论

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