Friday, December 8, 2017

DELPHI - How enumerate all directories

Use faDirectory setting in FindFirst():
var
  recSearch : TSearchRec;
  sUNC : string;
...
begin
  { get unc path to base directory }

  sUnc := DB.QSetup_Globalupdate_unc.AsString;

  { enumerate only directories }

  i := FindFirst( sUNC + '*.*' , faDirectory, recSearch );
  while i = 0 do
    begin
      if recSearch.name[1] <> '.' then
        begin
          try
            { do something; } 
          except
          end;
        end;

      { try find next }
      i := FindNext( recSearch );
    end;
  FindClose( recSearch );
...
end;

No comments:

Post a Comment