DEVELOPMENT EDITION · 769442725406
Library Reference
On this page

Ada.Directories

The host's directories and files by name, and searches of a directory (Ada RM A.16), with Verada's Modification_Seconds in place of Modification_Time.

Read the family guide for representation, selection and resource rules. The complete declaration page retains exact signatures/contracts; the source specification is the implementation baseline.

Availability and ownership

A predefined package: with it and call its operations. A procedure that changes the file system lists Name_Error and Use_Error in its Exceptional_Cases.

A client proof uses these contracts without proving the body again (see library assurance). Global => null excludes package-global effects, not changes made through an in out argument.

Import and instantiate

with Ada.Directories;
import Ada.Directories;

A Vibe module imports this unit's names with from Ada.Directories import Name; see library use across syntaxes. In Varc, keep each name's declared spelling and write & on arguments the call changes.

Contract and lifecycle reading

A Pre condition is the caller's obligation; a Post is what a normal return guarantees. What a postcondition does not state, a client cannot assume. Ghost functions are for contracts and ghost code. The family guide describes copying, lifetime, order and cost.

API 001

Status_Error (declaration) — Get_Next_Entry when the search has no entry left.

Declared interface:

Status_Error : exception renames Ada.IO_Exceptions.Status_Error;

API 002

Name_Error (declaration) — No such file or directory, or a name that cannot be one.

Declared interface:

Name_Error   : exception renames Ada.IO_Exceptions.Name_Error;

API 003

Use_Error (declaration) — The host refuses the operation (a directory that is not empty, a file that exists, no permission).

Declared interface:

Use_Error    : exception renames Ada.IO_Exceptions.Use_Error;

API 004

Device_Error (declaration) — Ada's device failure; Verada's operations report the host's refusals as Use_Error.

Declared interface:

Device_Error : exception renames Ada.IO_Exceptions.Device_Error;

API 005

Current_Directory (declaration) — The process's current directory, a full name.

Declared interface:

function Current_Directory return String
  with Global => Ada.Text_IO.File_System,
       Post => Current_Directory'Result'Length in 1 .. Verada.Storage.Length_Bound - 1;

API 006

Set_Directory (declaration) — The current directory changed to Directory.

Declared interface:

procedure Set_Directory (Directory : String)
  with Global => (In_Out => Ada.Text_IO.File_System),
       Exceptional_Cases => (Name_Error | Use_Error => True);

API 007

Create_Directory (declaration) — A new directory; Use_Error when it exists.

Declared interface:

procedure Create_Directory (New_Directory : String; Form : String := "")
  with Global => (In_Out => Ada.Text_IO.File_System),
       Exceptional_Cases => (Name_Error | Use_Error => True);

API 008

Delete_Directory (declaration) — An empty directory removed.

Declared interface:

procedure Delete_Directory (Directory : String)
  with Global => (In_Out => Ada.Text_IO.File_System),
       Exceptional_Cases => (Name_Error | Use_Error => True);

API 009

Create_Path (declaration) — Every directory on the path that is not there yet.

Declared interface:

procedure Create_Path (New_Directory : String; Form : String := "")
  with Global => (In_Out => Ada.Text_IO.File_System),
       Exceptional_Cases => (Name_Error | Use_Error => True);

API 010

Delete_Tree (declaration) — A directory removed with everything it holds.

Declared interface:

procedure Delete_Tree (Directory : String)
  with Global => (In_Out => Ada.Text_IO.File_System),
       Exceptional_Cases => (Name_Error | Use_Error => True);

API 011

Delete_File (declaration) — A file (not a directory) removed.

Declared interface:

procedure Delete_File (Name : String)
  with Global => (In_Out => Ada.Text_IO.File_System),
       Exceptional_Cases => (Name_Error | Use_Error => True);

API 012

Rename (declaration) — A file or directory given a new name, which must not exist.

Declared interface:

procedure Rename (Old_Name, New_Name : String)
  with Global => (In_Out => Ada.Text_IO.File_System),
       Exceptional_Cases => (Name_Error | Use_Error => True);

API 013

Copy_File (declaration) — An ordinary file's bytes copied to a new or replaced file.

Declared interface:

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);

API 014

Full_Name (declaration) — The name made absolute against the current directory, . and .. resolved; the file need not exist.

Declared interface:

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;

API 015

Simple_Name (declaration) — The name after its last /.

Declared interface:

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;

API 016

Containing_Directory (declaration) — The name before its last /: / at the root, . when it has none.

Declared interface:

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;

API 017

Extension (declaration) — The simple name's text after its last ., empty when it has none.

Declared interface:

function Extension (Name : String) return String
  with Global => null,
       Post => Extension'Result'Length <= Name'Length + 1 and then Extension'Result'First = 1;

API 018

Base_Name (declaration) — The simple name without its extension.

Declared interface:

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;

API 019

Compose (declaration) — A directory, a name and an extension joined with / and ..

Declared interface:

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;

API 020

Name_Case_Kind (declaration) — How the host compares names: case-sensitive, insensitive or preserving.

Declared interface:

type Name_Case_Kind is (Unknown, Case_Sensitive, Case_Insensitive, Case_Preserving);

API 021

Name_Case_Equivalence (declaration) — How the file system holding Name compares names.

Declared interface:

function Name_Case_Equivalence (Name : String) return Name_Case_Kind
  with Global => Ada.Text_IO.File_System,
       Pre => Exists (Name);

API 022

File_Kind (declaration) — A directory, an ordinary file, or anything else (a device, a pipe).

Declared interface:

type File_Kind is (Directory, Ordinary_File, Special_File);

API 023

File_Size (declaration) — A file's size in bytes.

Declared interface:

type File_Size is range 0 .. Long_Long_Integer'Last;

API 024

Exists (declaration) — Whether a file or directory of that name exists.

Declared interface:

function Exists (Name : String) return Boolean
  with Global => Ada.Text_IO.File_System;

API 025

Kind (declaration) — The kind of an existing file.

Declared interface:

function Kind (Name : String) return File_Kind
  with Global => Ada.Text_IO.File_System,
       Pre => Exists (Name);

API 026

Size (declaration) — An existing file's size in bytes.

Declared interface:

function Size (Name : String) return File_Size
  with Global => Ada.Text_IO.File_System,
       Pre => Exists (Name);

API 027

Modification_Seconds (declaration) — Verada's: when an existing file last changed, in seconds since the epoch (Modification_Time is left out, B0501).

Declared interface:

function Modification_Seconds (Name : String) return Long_Long_Integer
  with Global => Ada.Text_IO.File_System,
       Pre => Exists (Name);

API 028

Directory_Entry_Type (declaration) — An entry a search returned: its names, kind, size and time as they were when it was read.

Declared interface:

type Directory_Entry_Type is limited private;

API 029

Filter_Type (declaration) — The kinds of file a search returns.

Declared interface:

type Filter_Type is array (File_Kind) of Boolean;

API 030

Search_Type (declaration) — A search of a directory, not open until Start_Search opens it.

Declared interface:

type Search_Type is limited private
  with Default_Initial_Condition => not Is_Open (Search_Type);

API 031

Is_Open (declaration) — Verada's: whether a search was started and not ended.

Declared interface:

function Is_Open (Search : Search_Type) return Boolean
  with Global => null;

API 032

Start_Search (declaration) — A search of Directory for the names Pattern matches (*, ?, [...]; empty for all) whose kinds Filter holds, in byte order.

Declared interface:

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));

API 033

End_Search (declaration) — The search ended and its names released.

Declared interface:

procedure End_Search (Search : in out Search_Type)
  with Global => (In_Out => Ada.Text_IO.File_System),
       Post => not Is_Open (Search);

API 034

More_Entries (declaration) — Whether Get_Next_Entry has an entry to return.

Declared interface:

function More_Entries (Search : Search_Type) return Boolean
  with Global => Ada.Text_IO.File_System;

API 035

Get_Next_Entry (declaration) — The search's next entry; Status_Error when there is none.

Declared interface:

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);

API 036

Search (declaration) — Process called with each entry of a search; a procedure called through an access value uses no globals.

Declared interface:

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);

API 037

Simple_Name (declaration) — An entry's simple name.

Declared interface:

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);

API 038

Full_Name (declaration) — An entry's full name.

Declared interface:

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);

API 039

Kind (declaration) — An entry's kind.

Declared interface:

function Kind (Directory_Entry : Directory_Entry_Type) return File_Kind
  with Global => null;

API 040

Size (declaration) — An entry's size in bytes.

Declared interface:

function Size (Directory_Entry : Directory_Entry_Type) return File_Size
  with Global => null;

API 041

Modification_Seconds (declaration) — Verada's: when an entry's file last changed, in seconds since the epoch.

Declared interface:

function Modification_Seconds (Directory_Entry : Directory_Entry_Type) return Long_Long_Integer
  with Global => null;