ADA - Searching a directory with a pattern - not returning as it should

Viewed 180

This section of my program is supposed to list all files within the directory containing ".txt" in the name but it's not returning anything when run. If I delete ".txt" and leave it as an empty string "" then it works perfectly and returns all file names including the .txt files so I can't figure out what I'm doing wrong here.

  procedure Search_Directory is
      use Ada.Directories;
      
      procedure Write_Search_Item(Search_Item : in Directory_Entry_Type) is
      begin
         Put(Item => Simple_Name(Directory_Entry => Search_Item));
         New_Line;
      end Write_Search_Item;

      Filter : Constant Filter_Type := (Ordinary_File => True,
                                        Special_File => False,
                                        Directory => True);         
   begin
      Search(Directory => Current_Directory,
             Pattern => (".txt"),
             Filter => Filter,
             Process => Write_Search_Item'Access);           
   end Search_Directory;
1 Answers

The Search function, defined in the package Ada.Directories, takes a pattern argument which is either a null string or a form that is implementation-defined RM A.16 (111/ 2). In GNAT, this pattern is supposed to be a regular expression (see also here) described in System.Regexp (see also here, second grammar, a "globbing pattern").

Related