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 把pf8bit位图变换成pf24bit位图

Delphi 返回程序执行参数的例子

Delphi bytetype-单双字节判断

Delphi 如何判断clipboard剪切板中的内容的类型

Delphi firedac 另存json

Delphi 判断特定字符是为单字节还是双字节

Delphi winapi: inflaterect - 改变矩形大小

Delphi webbrowser1使用进度条查看浏览器状态

Delphi 自动升级组件autoupgrader简单教程

Delphi 金木水火土 生克用法

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



打赏

取消

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

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

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

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

评论

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