Package: Ada.Directories.Searches

Dependencies

pragma License (Modified_GPL);

with Ada.Calendar;

Description

(c) Martin M. Dowie, 2004

Non-standard extension to provide common search facilities.


Header

package Ada.Directories.Searches is
 

Type Summary

Access_Option_Type
Size_Option_Type
Time_Option_Type

Other Items:

type Access_Option_Type is
   (Created, Modified, Accessed);
Type of file access checks that can be made.

type Size_Option_Type is
   (Atleast, Atmost);
Type of size checks that can be made.

type Time_Option_Type is
   (Before, On_Or_Before, On, On_Or_After, After);
Type of checks that can be made on time attribute.

procedure Do_Nothing (To : in String);
pragma Inline (Do_Nothing);
Until Ada200Y, this is the best we can do.

generic

   with procedure Action (Item :        Directory_Entry_Type;
                          Quit : in out Boolean);

   with procedure Directory_Change (To : in String)
           is Do_Nothing;

procedure Generic_Find (Name      : in String;
                        Extension : in String;
                        Directory : in String      := "";
                        Filter    : in Filter_Type := (others => True);
                        Recursive : in Boolean     := False);
Provides a canonical iterator that will process each directory entry found within a directory. The processing may be stopped by the users call-back routine.

Example 1: Find all ".ads" files on drive "C"

   declare
      use Ada;
      procedure Put_Line (Item :        Directories.Directory_Entry_Type;
                          Quit : in out Boolean) is
      begin
         Put_Line ("+++ Found file: " & Directories.Simple_Name (Item));
      end Put_Line;

      procedure Find is
         new Directories.Searches.Generic_Find (Put_Line);
   begin
      Find (Name      => "*",
            Directory => "C:\",
            Extension => "ads",
            Recursive => True);
   end;
Example 2: Find all files on drive "C"
   declare
      use Ada;
      procedure Put_Line (Item :        Directories.Directory_Entry_Type;
                          Quit : in out Boolean) is
      begin
         Put_Line ("+++ Found file: " & Directories.Simple_Name (Item));
      end Put_Line;

      procedure Find is
         new Directories.Searches.Generic_Find (Put_Line);
   begin
      Find (Name      => "*",
            Directory => "C:\",
            Extension => "",
            Recursive => True);
   end;
Example 3: Find all files with an extension on drive "C"
   declare
      use Ada;
      procedure Put_Line (Item :        Directories.Directory_Entry_Type;
                          Quit : in out Boolean) is
      begin
         Put_Line ("+++ Found file: " & Directories.Simple_Name (Item));
      end Put_Line;

      procedure Find is
         new Directories.Searches.Generic_Find (Put_Line);
   begin
      Find (Name      => "*",
            Directory => "C:\",
            Extension => "*",
            Recursive => True);
   end;

generic

   with procedure Action (Item :        Directory_Entry_Type;
                          Quit : in out Boolean);

   with procedure Directory_Change (To : in String)
           is Do_Nothing;

procedure Generic_Find_Between (Name          : in String;
                                From,
                                To            : in Ada.Calendar.Time;
                                Extension     : in String;
                                Access_Option : in Access_Option_Type :=
                                   Modified;
                                Directory     : in String      := "";
                                Filter        : in Filter_Type :=
                                   (others => True);
                                Recursive     : in Boolean     := False);
Finds files which have been modified within a given time period, with the appropriate Name in a given directory.

generic

   with procedure Action (Item :        Directory_Entry_Type;
                          Quit : in out Boolean);

   with procedure Directory_Change (To : in String)
           is Do_Nothing;

procedure Generic_Find_Since (Name          : in String;
                              Extension     : in String;
                              Since         : in Ada.Calendar.Time;
                              Access_Option : in Access_Option_Type :=
                                 Modified;
                              Time_Option   : in Time_Option_Type :=
                                 On_Or_After;
                              Directory     : in String      := "";
                              Filter        : in Filter_Type :=
                                 (others => True);
                              Recursive     : in Boolean     := False);
Finds files which have been modified since a given time, with the appropriate Name in a given directory.

generic

   with procedure Action (Item :        Directory_Entry_Type;
                          Quit : in out Boolean);

   with procedure Directory_Change (To : in String)
           is Do_Nothing;

procedure Generic_Find_Size (Name        : in String;
                             Extension   : in String;
                             Size        : in File_Size;
                             Size_Option : in Size_Option_Type := Atleast;
                             Directory   : in String      := "";
                             Filter      : in Filter_Type :=
                                (others => True);
                             Recursive   : in Boolean     := False);
Finds files of a given size, with the appropriate Name in a given Directory.
end Ada.Directories.Searches;