1with Ada.Calendar; 2with Ada.Directories; 3 4with Ada.Iterator_Interfaces; 5 6package Iter5_Pkg is 7 8 subtype Size is Ada.Directories.File_Size; 9 10 type Folder is new String; 11 12 function Folder_Separator return Character; 13 14 function "+" (Directory : String) return Folder; 15 16 function "+" (Left, Right : String) return Folder; 17 18 function "+" (Left : Folder; 19 Right : String) return Folder; 20 21 function Composure (Directory : Folder; 22 Filename : String; 23 Extension : String) return String; 24 25 function Composure (Directory : String; 26 Filename : String; 27 Extension : String) return String; 28 -- no exception 29 30 function Base_Name_Of (Name : String) return String 31 renames Ada.Directories.Base_Name; 32 33 function Extension_Of (Name : String) return String 34 renames Ada.Directories.Extension; 35 36 function Containing_Directory_Of (Name : String) return String 37 renames Ada.Directories.Containing_Directory; 38 39 function Exists (Name : String) return Boolean; 40 -- no exception 41 42 function Size_Of (Name : String) return Size renames Ada.Directories.Size; 43 44 function Directory_Exists (Name : String) return Boolean; 45 -- no exception 46 47 function Modification_Time_Of (Name : String) return Ada.Calendar.Time 48 renames Ada.Directories.Modification_Time; 49 50 function Is_Newer (The_Name : String; 51 Than_Name : String) return Boolean; 52 53 procedure Delete (Name : String); 54 -- no exception if no existance 55 56 procedure Create_Directory (Path : String); 57 -- creates the whole directory path 58 59 procedure Delete_Directory (Name : String); -- including contents 60 -- no exception if no existance 61 62 procedure Rename (Old_Name : String; 63 New_Name : String) renames Ada.Directories.Rename; 64 65 procedure Copy (Source_Name : String; 66 Target_Name : String; 67 Form : String := "") 68 renames Ada.Directories.Copy_File; 69 70 function Is_Leaf_Directory (Directory : String) return Boolean; 71 72 procedure Iterate_Over_Leaf_Directories (From_Directory : String; 73 Iterator : access procedure 74 (Leaf_Directory : String)); 75 76 function Found_Directory (Simple_Name : String; 77 In_Directory : String) return String; 78 79 Not_Found : exception; 80 81 Name_Error : exception renames Ada.Directories.Name_Error; 82 Use_Error : exception renames Ada.Directories.Use_Error; 83 84 ------------------------ 85 -- File Iterator Loop -- 86 ------------------------ 87 -- Example: 88 -- for The_Filename of Iter5_Pkg.Iterator_For ("C:\Program_Files") loop 89 -- Log.Write (The_Filename); 90 -- end loop; 91 92 type Item (Name_Length : Natural) is limited private; 93 94 function Iterator_For (Name : String) return Item; 95 96private 97 type Cursor; 98 99 function Has_More (Data : Cursor) return Boolean; 100 101 package List_Iterator_Interfaces is 102 new Ada.Iterator_Interfaces (Cursor, Has_More); 103 104 function Iterate (The_Item : Item) 105 return List_Iterator_Interfaces.Forward_Iterator'class; 106 107 type Cursor_Data is record 108 Has_More : Boolean := False; 109 Position : Ada.Directories.Search_Type; 110 end record; 111 112 type Cursor is access all Cursor_Data; 113 114 function Constant_Reference (The_Item : aliased Item; 115 Unused_Index : Cursor) return String; 116 117 type Item (Name_Length : Natural) is tagged limited record 118 Name : String(1..Name_Length); 119 Actual : Ada.Directories.Directory_Entry_Type; 120 Data : aliased Cursor_Data; 121 end record 122 with 123 Constant_Indexing => Constant_Reference, 124 Default_Iterator => Iterate, 125 Iterator_Element => String; 126 127end Iter5_Pkg; 128