On this page
- Current_Directory
- Set_Directory
- Create_Directory
- Delete_Directory
- Create_Path
- Delete_Tree
- Delete_File
- Rename
- Copy_File
- Full_Name
- Simple_Name
- Containing_Directory
- Extension
- Base_Name
- Compose
- Name_Case_Kind
- Name_Case_Equivalence
- File_Kind
- File_Size
- Exists
- Kind
- Size
- Modification_Seconds
- Directory_Entry_Type
- Filter_Type
- Search_Type
- Is_Open
- Start_Search
- End_Search
- More_Entries
- Get_Next_Entry
- Search
- Simple_Name
- Full_Name
- Kind
- Size
- Modification_Seconds
Package Ada.Directories
Verada predefined library: Ada.Directories (Ada RM A.16): the host's directories and files, by name, and searches of a directory. The host's files are Text_IO's File_System state, so these operations take their order with Text_IO's from the flow contracts. A procedure that changes the file system propagates Name_Error (no such file or directory, or a name that cannot be one) or Use_Error (the host refuses), as Ada's does, and its Exceptional_Cases say so; a function propagates no exception, so what Ada raises Name_Error for is a precondition (Exists). Verada leaves out Modification_Time, whose Ada.Calendar time depends on the host's zone, and adds Modification_Seconds, the time in seconds since the epoch (1970-01-01 00:00:00 UTC). The name functions (Simple_Name, Containing_Directory, Extension, Base_Name, Compose) work on the text alone, with / as the separator, and take any string (an empty name has an empty simple name, and . contains it).
Status_Error : exception renames Ada.IO_Exceptions.Status_Error;Name_Error : exception renames Ada.IO_Exceptions.Name_Error;Use_Error : exception renames Ada.IO_Exceptions.Use_Error;Device_Error : exception renames Ada.IO_Exceptions.Device_Error;Current_Directory
function Current_Directory return String
with Global => Ada.Text_IO.File_System,
Post => Current_Directory'Result'Length in 1 .. Verada.Storage.Length_Bound - 1;Set_Directory
procedure Set_Directory (Directory : String)
with Global => (In_Out => Ada.Text_IO.File_System),
Exceptional_Cases => (Name_Error | Use_Error => True);Create_Directory
procedure Create_Directory (New_Directory : String; Form : String := "")
with Global => (In_Out => Ada.Text_IO.File_System),
Exceptional_Cases => (Name_Error | Use_Error => True);Delete_Directory
procedure Delete_Directory (Directory : String)
with Global => (In_Out => Ada.Text_IO.File_System),
Exceptional_Cases => (Name_Error | Use_Error => True);(an empty directory only: Delete_Tree removes one with what it holds)
Create_Path
procedure Create_Path (New_Directory : String; Form : String := "")
with Global => (In_Out => Ada.Text_IO.File_System),
Exceptional_Cases => (Name_Error | Use_Error => True);every directory on the path that is not there yet
Delete_Tree
procedure Delete_Tree (Directory : String)
with Global => (In_Out => Ada.Text_IO.File_System),
Exceptional_Cases => (Name_Error | Use_Error => True);Delete_File
procedure Delete_File (Name : String)
with Global => (In_Out => Ada.Text_IO.File_System),
Exceptional_Cases => (Name_Error | Use_Error => True);Rename
procedure Rename (Old_Name, New_Name : String)
with Global => (In_Out => Ada.Text_IO.File_System),
Exceptional_Cases => (Name_Error | Use_Error => True);(Use_Error when New_Name is an existing file)
Copy_File
procedure Copy_File (Source_Name, Target_Name : String; Form : String := "")
with Global => (In_Out => Ada.Text_IO.File_System),
Exceptional_Cases => (Name_Error | Use_Error => True);Full_Name
function Full_Name (Name : String) return String
with Global => Ada.Text_IO.File_System,
Post => Full_Name'Result'Length in 1 .. Verada.Storage.Length_Bound - 1;the name made absolute against the current directory, with . and .. resolved (the file need not exist)
Simple_Name
function Simple_Name (Name : String) return String
with Global => null,
Post => Simple_Name'Result'Length <= Name'Length + 1 and then Simple_Name'Result'First = 1;the name after its last / (the name itself when it ends in one or has none)
Containing_Directory
function Containing_Directory (Name : String) return String
with Global => null,
Post => Containing_Directory'Result'Length <= Name'Length + 1 and then Containing_Directory'Result'First = 1;the name before its last / (/ for a name at the root, . for one with no /)
Extension
function Extension (Name : String) return String
with Global => null,
Post => Extension'Result'Length <= Name'Length + 1 and then Extension'Result'First = 1;the simple name's text after its last . (empty when there is none)
Base_Name
function Base_Name (Name : String) return String
with Global => null,
Post => Base_Name'Result'Length <= Name'Length + 1 and then Base_Name'Result'First = 1;the simple name without its extension and the . before it
Compose
function Compose (Containing_Directory : String := ""; Name : String; Extension : String := "") return String
with Global => null,
Post => Compose'Result'Length <= Containing_Directory'Length + Name'Length + Extension'Length + 2
and then Compose'Result'First = 1,
Pre => Containing_Directory'Length < 2 * Verada.Storage.Length_Bound
and then Name'Length < 2 * Verada.Storage.Length_Bound
and then Extension'Length < 2 * Verada.Storage.Length_Bound;Containing_Directory, /, Name, and . and Extension when there is one (each part shorter than twice the longest string memory holds, so that a name composed of names can be composed again)
Name_Case_Kind
type Name_Case_Kind is (Unknown, Case_Sensitive, Case_Insensitive, Case_Preserving);Name_Case_Equivalence
function Name_Case_Equivalence (Name : String) return Name_Case_Kind
with Global => Ada.Text_IO.File_System,
Pre => Exists (Name);File_Kind
type File_Kind is (Directory, Ordinary_File, Special_File);File_Size
type File_Size is range 0 .. Long_Long_Integer'Last;Exists
function Exists (Name : String) return Boolean
with Global => Ada.Text_IO.File_System;Kind
function Kind (Name : String) return File_Kind
with Global => Ada.Text_IO.File_System,
Pre => Exists (Name);Size
function Size (Name : String) return File_Size
with Global => Ada.Text_IO.File_System,
Pre => Exists (Name);Modification_Seconds
function Modification_Seconds (Name : String) return Long_Long_Integer
with Global => Ada.Text_IO.File_System,
Pre => Exists (Name);(Verada's: the time the file was last changed, in seconds since the epoch)
Directory_Entry_Type
type Directory_Entry_Type is limited private;an entry a search returned (an entry no search has filled: empty names, an ordinary file of size 0)
Filter_Type
type Filter_Type is array (File_Kind) of Boolean;Search_Type
type Search_Type is limited private
with Default_Initial_Condition => not Is_Open (Search_Type);a search, not open until Start_Search opens it
Is_Open
function Is_Open (Search : Search_Type) return Boolean
with Global => null;(Verada's: the search was started and not ended)
Start_Search
procedure Start_Search (Search : in out Search_Type; Directory : String; Pattern : String;
Filter : Filter_Type := (others => True))
with Global => (In_Out => Ada.Text_IO.File_System),
Post => Is_Open (Search),
Exceptional_Cases => (Name_Error | Use_Error => not Is_Open (Search));the entries of Directory whose simple names match Pattern (* any characters, ? one, [...] one of a set; an empty Pattern matches every name) and whose kinds Filter holds, in the order of their names' bytes, as they were when the search started
End_Search
procedure End_Search (Search : in out Search_Type)
with Global => (In_Out => Ada.Text_IO.File_System),
Post => not Is_Open (Search);More_Entries
function More_Entries (Search : Search_Type) return Boolean
with Global => Ada.Text_IO.File_System;Get_Next_Entry
procedure Get_Next_Entry (Search : in out Search_Type; Directory_Entry : out Directory_Entry_Type)
with Global => (In_Out => Ada.Text_IO.File_System),
Post => Is_Open (Search) = Is_Open (Search)'Old,
Exceptional_Cases => (Status_Error => True);the next entry; Status_Error when there is none
Search
procedure Search (Directory : String; Pattern : String; Filter : Filter_Type := (others => True);
Process : not null access procedure (Directory_Entry : Directory_Entry_Type))
with Global => (In_Out => Ada.Text_IO.File_System),
Exceptional_Cases => (Name_Error | Use_Error => True);Process called with each entry a search of Directory for Pattern and Filter returns
Simple_Name
function Simple_Name (Directory_Entry : Directory_Entry_Type) return String
with Global => null,
Post => Simple_Name'Result'Length < Verada.Storage.Length_Bound
and then (Simple_Name'Result'Length = 0 or else Simple_Name'Result'First = 1);Full_Name
function Full_Name (Directory_Entry : Directory_Entry_Type) return String
with Global => null,
Post => Full_Name'Result'Length < Verada.Storage.Length_Bound
and then (Full_Name'Result'Length = 0 or else Full_Name'Result'First = 1);Kind
function Kind (Directory_Entry : Directory_Entry_Type) return File_Kind
with Global => null;Size
function Size (Directory_Entry : Directory_Entry_Type) return File_Size
with Global => null;Modification_Seconds
function Modification_Seconds (Directory_Entry : Directory_Entry_Type) return Long_Long_Integer
with Global => null;(Verada's, as for a name)