0

I am using the following code to get a list of files and folders. I cannot seem to get the list to include hidden files and folders.

procedure GetAllSubFolders(sPath: String; Listbox: TListbox);
var
  Path: String;
  Rec: TSearchRec;
begin
  try
    Path := IncludeTrailingBackslash(sPath);
    if FindFirst(Path + '*.*', faDirectory, Rec) = 0 then
    try
      repeat
        if (Rec.Name <> '.') and (Rec.Name <> '..') then
        begin
          if (ExtractFileExt(Path + Rec.Name) <> '') And (Directoryexists(Path + Rec.Name + '\') = False) then
          Begin
            Listbox.Items.Add(Path+Rec.Name);
          End;
          GetAllSubFolders(Path + Rec.Name, Listbox);
        end;
      until FindNext(Rec) <> 0;
    finally
      FindClose(Rec);
    end;
  except
    on e: Exception do
      Showmessage('Err : TForm1.GetAllSubFolders - ' + e.Message);
  end;
end;
Kromster
  • 7,181
  • 7
  • 63
  • 111
user3510818
  • 103
  • 1
  • 12
  • 6
    Take a look into the [`FindFirst`](http://docwiki.embarcadero.com/Libraries/XE5/en/System.SysUtils.FindFirst) function reference, specifically the `Attr` parameter description. You'll surely find the answer there... – TLama May 28 '14 at 19:27
  • 1
    You can use the functionality of IOUtils – David Heffernan May 28 '14 at 19:28
  • @TLama excelent. Didnt think to look at the "findfirst" part. Just changed it to if FindFirst(Path + '*.*', faAnyFile, Rec) and the problem was solved – user3510818 May 28 '14 at 19:34

1 Answers1

3

Here's a quote from Delphi help:

The Attr parameter specifies the special files to include in addition to all normal files. Choose from these file attribute constants when specifying the Attr parameter.

You should use faDirectory or faHidden or other flags instead of just faDirectory and read help on FindFirst!

Kromster
  • 7,181
  • 7
  • 63
  • 111
AlekXL
  • 81
  • 1