How to get the names of subfolders of a directory that also contain periods in the name?

I am trying to populate a list of strings with all the folder names inside the directory.

Below is a snippet of how I was able to do this:

var
  SL: TStringList;
  SearchAttr: LongInt;
  SR: TSearchRec;
begin
  SL := TStringList.Create;
  try
    SearchAttr := (faDirectory);

    if FindFirst(Directory + '\*.', SearchAttr, SR) = 0 then
    begin
      try
        repeat
          if (SR.Attr and faDirectory) <> 0 then
          begin
            if (SR.Name <> '.') and (SR.Name <> '..') then
            begin
              SL.Add(Directory + SR.Name);
            end;
          end;
        until
          FindNext(Sr) <> 0;
        finally
          FindClose(SR);
        end;
      end;
    end;

    // do something with string list folder names      
  finally
    SL.Free;
  end;
end;

The parent folder I accessed contains 220 auxiliary folders, but only 216 folder names were added to the subroutine. After some comparisons and debugging, I noticed that the 4 folder names that were not added contained dots in the names.

For testing, I created a folder called "Test Folder", and inside I added 9 more new folders with the name:

  • Folder 1
  • Folder 2
  • Folder 3
  • Folder 4
  • Folder 5
  • Folder .6
  • Folder 7
  • FOLDER 8
  • Folder 9

When using the "test folder" as the parent directory, it adds only the following subfolders:

  • Folder 1
  • Folder 2
  • Folder 3
  • Folder 4
  • Folder 5
  • Folder 7
  • Folder 9

SR.Name <> '.', SR.Name <> '..' SR.Name[1] <> '.' .. .

, ?

+4
1

'*.' '*'

. , , .

+6

All Articles