delphi中怎么判断一个文件夹是否为空  
官方Delphi 学习QQ群: 682628230(三千人)
频道

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;

推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.043555021286011 seconds