Update for FSEnum

Since some people asked me to improve FSEnum unit (see this post). I decided to give it another go and add some features and improve the others.

So what’s new?

  • Optional Boolean parameter for all methods that tells the enumerator whether to return the relative paths (like it did before) or absolute ones.
  • There are two levels of “mask matching” (if the enumeration is recursive). The first level allows everything to pass since you need to recurse into all directories. The real mask matching is done at the second level using the TMask (unit Masks).
  • Two new methods (overloaded): FileSystemEntries which returns an enumerable over TFileSystemEntry structure.
  • A new TFileSystemEntry structure that contains more information about a file/directory.

The next example shows the use of TDirectory.FileSystemEntries method:

var
  Entry: TFileSystemEntry;

begin
  { Show all read-only executable files on drive I: bigger than 1MB }
  for Entry in TDirectory.FileSystemEntries('i:', '*.exe', true) do
    if (Entry.Size > 1000000) and Entry.IsReadOnly then WriteLn(Entry.FullName);

  ReadLn;
end.

The unit is the same (has been updated!)  and can be found here: [download#40]

5 Comments

  1. Hello, Alex!

    Thank you for such a quick update!
    And this question: Do you plan to include FSEnum in DeHL, using its features?
    Then could simply manipulate the list of files, using Select, Where, Intersect, Take, etc.

    That would be excellent!

    Sincerely, Dmitry.

  2. It is a pity that there still may not be used as follows:
    for Entry in TDirectory.FileSystemEntries ( ‘i:’, ‘*Source*’, ‘*.pas’, true) do …

    Sincerely, Dmitry.

  3. @Dmitry:

    for Entry in TDirectory.FileSystemEntries ( ‘i:’, ‘*Source*’, ‘*.pas’, true) do …

    will not work as expected. Because you can have multiple levels of directories. and *Source* will only find _source_ at any given level of depth…

    As for DeHL, yes, I do plan to include it into DeHL at some point. Right now I am waiting for a few issues to be fixed in the compiler.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.