Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8667227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:54:56+00:00 2026-06-12T17:54:56+00:00

TDirectory.GetFiles has a parameter called SearchPattern . Embarcadero’s documentation says The mask used when

  • 0

TDirectory.GetFiles has a parameter called SearchPattern. Embarcadero’s documentation says

The mask used when matching file names (for example, “*.exe” matches all the executable files).

However, I want to pass multiple file types. I get those types from a FilterComboBox.Mask. So, it is a string that looks like '*.txt;*.rtf;*.doc'.

I have tried to pass that string directly to GetFiles and it doesn’t work. Do I have to parse it, break it into pieces and feed every individual piece to GetFiles?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T17:54:57+00:00Added an answer on June 12, 2026 at 5:54 pm

    The RTL code behind GetFiles calls Masks.MatchesMask to test for a match to your search pattern. This function only supports masking against a single mask.

    The alternative is to use the GetFiles overload that admits a TFilterPredicate. You supply a predicate that tests whether or not a name matches your pattern.

    uses
      StrUtils, Types, Masks, IOUtils;
    
    function MyGetFiles(const Path, Masks: string): TStringDynArray;
    var
      MaskArray: TStringDynArray;
      Predicate: TDirectory.TFilterPredicate;
    begin
      MaskArray := SplitString(Masks, ';');
      Predicate :=
        function(const Path: string; const SearchRec: TSearchRec): Boolean
        var
          Mask: string;
        begin
          for Mask in MaskArray do
            if MatchesMask(SearchRec.Name, Mask) then
              exit(True);
          exit(False);
        end;
      Result := TDirectory.GetFiles(Path, Predicate);
    end;
    

    Do note that MatchesMask creates and destroys a heap allocated TMask every time it is called. I can well imagine that being a performance bottleneck over a long search. In which case you could create an array of TMask objects from MaskArray. And use those in the predicate to test. I’ve no idea whether this is a valid concern or not, just something that occurred to me whilst perusing the code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the syntax for setting multiple file-extensions as searchPattern on Directory.GetFiles() ? For
Directory.GetFiles(targetDirectory); Using the above code we get the names( i.e full path) of all
Somehow a file has appeared in one of my directories, and it has space
Directory.GetFiles method fails on the first encounter with a folder it has no access
I have the following code: string[] files = Directory.GetFiles(@C:\Notes, *.txt, SearchOption.TopDirectoryOnly); foreach(string file in
Following code transfer file successfully, but does not print in lable that it has
I want to check if a file in the directory I pass has a
I'm working on a C# script that has to access a random file during
Our Windows file server has an archive service installed that stubs files that have
Directory.GetFiles() returns all files, even those that are marked as hidden. Is there a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.