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通过spcomm com口发短信包括pud编码解码

Delphi 图像灰度化处理

Delphi xe7写的一个http post的小测试程序

Delphi获取系统安全软件信息

Delphi使用idhttp.get('') 造成假死(堵塞),请问线程idhttp怎么才能做到不出错?

Delphi 万能模糊查询

Delphi firemonkey 保存图片到jpg的方法 bmp转jpg

Delphi 屏幕截屏

Delphi剪切板-监视剪贴板

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



打赏

取消

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

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

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

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

评论

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