Skip to content

TDirectory.GetDirectories returns files too

Summary

TDirectory.GetDirectories returns all files and folders inside the specified path.

System Information

  • Operating system: Alt.Linux 10.4
  • Processor architecture: x86-64
  • Compiler version: trunk (2b6c136d)
  • Device: Computer

Example Project

Please, take a look to attached sample project: test2.zip

What is the current bug behavior?

TDirectory.GetDirectories returns all files and folders inside the specified path.

What is the expected (correct) behavior?

TDirectory.GetDirectories returns directories only

Possible fixes

In current code, the TDirectory uses a faDirectory to filter the content, but (according the documentation: https://www.freepascal.org/docs-html/rtl/sysutils/findfirst.html - specifying faDirectory as a value for Attr does not mean that only directories will be returned. Normal files and directories will be returned), it will not filter the files.

In Delphi, TDirectory uses internal predicate to filter the directory/files in this case. So, I has implemented similar solution: IOUtils.patch

Edited by Artem Izmaylov
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information