A.16 The Package Directories
This Reference Manual output has not been verified, and may contain omissions or errors. Report any problems on the tracking issue
The package Directories provides operations for manipulating files and directories, and their names.
Static Semantics
2/2The library package Directories has the following declaration:
with Ada.IO_Exceptions;
with Ada.Calendar;
package Ada.Directories
with Global => in out synchronized is
4/2-- Directory and file operations:
5/2function Current_Directory return String;
6/2procedure Set_Directory (Directory : in String);
7/2procedure Create_Directory (New_Directory : in String;
Form : in String := "");
8/2procedure Delete_Directory (Directory : in String);
9/2procedure Create_Path (New_Directory : in String;
Form : in String := "");
10/2procedure Delete_Tree (Directory : in String);
11/2procedure Delete_File (Name : in String);
12/2procedure Rename (Old_Name, New_Name : in String);
13/2procedure Copy_File (Source_Name,
Target_Name : in String;
Form : in String := "");
14/2-- File and directory name operations:
15/5function Full_Name (Name : in String) return String
with Nonblocking;
16/5function Simple_Name (Name : in String) return String
with Nonblocking;
17/5function Containing_Directory (Name : in String) return String
with Nonblocking;
18/5function Extension (Name : in String) return String
with Nonblocking;
19/5function Base_Name (Name : in String) return String
with Nonblocking;
20/5function Compose (Containing_Directory : in String := "";
Name : in String;
Extension : in String := "") return String
with Nonblocking;
20.1/3type Name_Case_Kind is
(Unknown, Case_Sensitive, Case_Insensitive, Case_Preserving);
20.2/3function Name_Case_Equivalence (Name : in String) return Name_Case_Kind;
21/2-- File and directory queries:
22/2type File_Kind is (Directory, Ordinary_File, Special_File);
23/2type File_Size is range 0 .. implementation-defined;
24/2function Exists (Name : in String) return Boolean;
25/2function Kind (Name : in String) return File_Kind;
26/2function Size (Name : in String) return File_Size;
27/2function Modification_Time (Name : in String) return Ada.Calendar.Time;
28/2-- Directory searching:
29/2type Directory_Entry_Type is limited private;
30/2type Filter_Type is array (File_Kind) of Boolean;
31/2type Search_Type is limited private;
32/2procedure Start_Search (Search : in out Search_Type;
Directory : in String;
Pattern : in String;
Filter : in Filter_Type := (others => True));
33/2procedure End_Search (Search : in out Search_Type);
34/2function More_Entries (Search : in Search_Type) return Boolean;
35/2procedure Get_Next_Entry (Search : in out Search_Type;
Directory_Entry : out Directory_Entry_Type);
36/5procedure Search (
Directory : in String;
Pattern : in String;
Filter : in Filter_Type := (others => True);
Process : not null access procedure (
Directory_Entry : in Directory_Entry_Type))
with Allows_Exit;
37/2-- Operations on Directory Entries:
38/2function Simple_Name (Directory_Entry : in Directory_Entry_Type)
return String;
39/2function Full_Name (Directory_Entry : in Directory_Entry_Type)
return String;
40/2function Kind (Directory_Entry : in Directory_Entry_Type)
return File_Kind;
41/2function Size (Directory_Entry : in Directory_Entry_Type)
return File_Size;
42/2function Modification_Time (Directory_Entry : in Directory_Entry_Type)
return Ada.Calendar.Time;
43/2Status_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;
44/3private
... -- not specified by the language
end Ada.Directories;
45/2External files may be classified as directories, special files, or ordinary files. A directory is an external file that is a container for files on the target system. A special file is an external file that cannot be created or read by a predefined Ada input-output package. External files that are not special files or directories are called ordinary files.
A file name is a string identifying an external file. Similarly, a directory name is a string identifying a directory. The interpretation of file names and directory names is implementation defined.
The full name of an external file is a full specification of the name of the file. If the external environment allows alternative specifications of the name (for example, abbreviations), the full name should not use such alternatives. A full name typically will include the names of all of the directories that contain the item. The simple name of an external file is the name of the item, not including any containing directory names. Unless otherwise specified, a file name or directory name parameter in a call to a predefined Ada input-output subprogram can be a full name, a simple name, or any other form of name supported by the implementation.
A root directory is a directory that has no containing directory.
The default directory is the directory that is used if a directory or file name is not a full name (that is, when the name does not fully identify all of the containing directories).
A directory entry is a single item in a directory, identifying a single external file (including directories and special files).
For each function that returns a string, the lower bound of the returned value is 1.
The following file and directory operations are provided:
function Current_Directory return String;
Returns the full directory name for the current default directory. The name returned shall be suitable for a future call to Set_Directory. The exception Use_Error is propagated if a default directory is not supported by the external environment.
procedure Set_Directory (Directory : in String);
Sets the current default directory. The exception Name_Error is propagated if the string given as Directory does not identify an existing directory. The exception Use_Error is propagated if the external environment does not support making Directory (in the absence of Name_Error) a default directory.
procedure Create_Directory (New_Directory : in String;
Form : in String := "");
Creates a directory with name New_Directory. The Form parameter can be used to give system-dependent characteristics of the directory; the interpretation of the Form parameter is implementation defined. A null string for Form specifies the use of the default options of the implementation of the new directory. The exception Name_Error is propagated if the string given as New_Directory does not allow the identification of a directory. The exception Use_Error is propagated if the external environment does not support the creation of a directory with the given name (in the absence of Name_Error) and form.
procedure Delete_Directory (Directory : in String);
Deletes an existing empty directory with name Directory. The exception Name_Error is propagated if the string given as Directory does not identify an existing directory. The exception Use_Error is propagated if the directory is not empty or the external environment does not support the deletion of the directory with the given name (in the absence of Name_Error).
procedure Create_Path (New_Directory : in String;
Form : in String := "");
Creates zero or more directories with name New_Directory. Each nonexistent directory named by New_Directory is created.[ For example, on a typical Unix system, Create_Path ("/usr/me/my"); would create directory "me" in directory "usr", then create directory "my" in directory "me".] The Form parameter can be used to give system-dependent characteristics of the directory; the interpretation of the Form parameter is implementation defined. A null string for Form specifies the use of the default options of the implementation of the new directory. The exception Name_Error is propagated if the string given as New_Directory does not allow the identification of any directory. The exception Use_Error is propagated if the external environment does not support the creation of any directories with the given name (in the absence of Name_Error) and form. If Use_Error is propagated, it is unspecified whether a portion of the directory path is created.
procedure Delete_Tree (Directory : in String);
Deletes an existing directory with name Directory. The directory and all of its contents (possibly including other directories) are deleted. The exception Name_Error is propagated if the string given as Directory does not identify an existing directory. The exception Use_Error is propagated if the external environment does not support the deletion of the directory or some portion of its contents with the given name (in the absence of Name_Error). If Use_Error is propagated, it is unspecified whether a portion of the contents of the directory is deleted.
procedure Delete_File (Name : in String);
Deletes an existing ordinary or special file with name Name. The exception Name_Error is propagated if the string given as Name does not identify an existing ordinary or special external file. The exception Use_Error is propagated if the external environment does not support the deletion of the file with the given name (in the absence of Name_Error).
procedure Rename (Old_Name, New_Name : in String);
Renames an existing external file (including directories) with name Old_Name to New_Name. The exception Name_Error is propagated if the string given as Old_Name does not identify an existing external file or if the string given as New_Name does not allow the identification of an external file. The exception Use_Error is propagated if the external environment does not support the renaming of the file with the given name (in the absence of Name_Error). In particular, Use_Error is propagated if a file or directory already exists with name New_Name.
procedure Copy_File (Source_Name,
Target_Name : in String;
Form : in String := "");
Copies the contents of the existing external file with name Source_Name to an external file with name Target_Name. The resulting external file is a duplicate of the source external file. The Form parameter can be used to give system-dependent characteristics of the resulting external file; the interpretation of the Form parameter is implementation defined. Exception Name_Error is propagated if the string given as Source_Name does not identify an existing external ordinary or special file, or if the string given as Target_Name does not allow the identification of an external file. The exception Use_Error is propagated if the external environment does not support creating the file with the name given by Target_Name and form given by Form, or copying of the file with the name given by Source_Name (in the absence of Name_Error). If Use_Error is propagated, it is unspecified whether a portion of the file is copied.
The following file and directory name operations are provided:
function Full_Name (Name : in String) return String;
Returns the full name corresponding to the file name specified by Name. The exception Name_Error is propagated if the string given as Name does not allow the identification of an external file (including directories and special files).
function Simple_Name (Name : in String) return String;
Returns the simple name portion of the file name specified by Name. The simple name of a root directory is a name of the root itself. The exception Name_Error is propagated if the string given as Name does not allow the identification of an external file (including directories and special files).
function Containing_Directory (Name : in String) return String;
Returns the name of the containing directory of the external file (including directories) identified by Name. (If more than one directory can contain Name, the directory name returned is implementation defined.) The exception Name_Error is propagated if the string given as Name does not allow the identification of an external file. The exception Use_Error is propagated if the external file does not have a containing directory.
function Extension (Name : in String) return String;
Returns the extension name corresponding to Name. The extension name is a portion of a simple name (not including any separator characters), typically used to identify the file class. If the external environment does not have extension names, then the null string is returned. The exception Name_Error is propagated if the string given as Name does not allow the identification of an external file.
function Base_Name (Name : in String) return String;
Returns the base name corresponding to Name. The base name is the remainder of a simple name after removing any extension and extension separators. The exception Name_Error is propagated if the string given as Name does not allow the identification of an external file (including directories and special files).
function Compose (Containing_Directory : in String := "";
Name : in String;
Extension : in String := "") return String;
Returns the name of the external file with the specified Containing_Directory, Name, and Extension. If Extension is the null string, then Name is interpreted as a simple name; otherwise, Name is interpreted as a base name. The exception Name_Error is propagated if:
- the string given as Containing_Directory is not null and does not allow the identification of a directory;
- the string given as Extension is not null and is not a possible extension;
- the string given as Name is not a possible simple name (if Extension is null) or base name (if Extension is nonnull); or
- the string given as Name is a root directory, and Containing_Directory or Extension is nonnull.
function Name_Case_Equivalence (Name : in String) return Name_Case_Kind;
Returns the file name equivalence rule for the directory containing Name. Raises Name_Error if Name is not a full name. Returns Case_Sensitive if file names that differ only in the case of letters are considered different names. If file names that differ only in the case of letters are considered the same name, then Case_Preserving is returned if names have the case of the file name used when a file is created; and Case_Insensitive is returned otherwise. Returns Unknown if the file name equivalence is not known.
The following file and directory queries and types are provided:
type File_Kind is (Directory, Ordinary_File, Special_File);
The type File_Kind represents the kind of file represented by an external file or directory.
type File_Size is range 0 .. implementation-defined;
The type File_Size represents the size of an external file.
function Exists (Name : in String) return Boolean;
Returns True if an external file represented by Name exists, and False otherwise. The exception Name_Error is propagated if the string given as Name does not allow the identification of an external file (including directories and special files).
function Kind (Name : in String) return File_Kind;
Returns the kind of external file represented by Name. The exception Name_Error is propagated if the string given as Name does not allow the identification of an existing external file.
function Size (Name : in String) return File_Size;
Returns the size of the external file represented by Name. The size of an external file is the number of stream elements contained in the file. If the external file is not an ordinary file, the result is implementation defined. The exception Name_Error is propagated if the string given as Name does not allow the identification of an existing external file. The exception Constraint_Error is propagated if the file size is not a value of type File_Size.
function Modification_Time (Name : in String) return Ada.Calendar.Time;
Returns the time that the external file represented by Name was most recently modified. If the external file is not an ordinary file, the result is implementation defined. The exception Name_Error is propagated if the string given as Name does not allow the identification of an existing external file. The exception Use_Error is propagated if the external environment does not support reading the modification time of the file with the name given by Name (in the absence of Name_Error).
The following directory searching operations and types are provided:
type Directory_Entry_Type is limited private;
The type Directory_Entry_Type represents a single item in a directory. These items can only be created by the Get_Next_Entry procedure in this package. Information about the item can be obtained from the functions declared in this package. A default-initialized object of this type is invalid; objects returned from Get_Next_Entry are valid.
type Filter_Type is array (File_Kind) of Boolean;
The type Filter_Type specifies which directory entries are provided from a search operation. If the Directory component is True, directory entries representing directories are provided. If the Ordinary_File component is True, directory entries representing ordinary files are provided. If the Special_File component is True, directory entries representing special files are provided.
type Search_Type is limited private;
The type Search_Type contains the state of a directory search. A default-initialized Search_Type object has no entries available (function More_Entries returns False). Type Search_Type needs finalization (see 7.6).
procedure Start_Search (Search : in out Search_Type;
Directory : in String;
Pattern : in String;
Filter : in Filter_Type := (others => True));
Starts a search in the directory named by Directory for entries matching Pattern and Filter. Pattern represents a pattern for matching file names. If Pattern is the null string, all items in the directory are matched; otherwise, the interpretation of Pattern is implementation defined. Only items that match Filter will be returned. After a successful call on Start_Search, the object Search may have entries available, but it may have no entries available if no files or directories match Pattern and Filter. The exception Name_Error is propagated if the string given by Directory does not identify an existing directory, or if Pattern does not allow the identification of any possible external file or directory. The exception Use_Error is propagated if the external environment does not support the searching of the directory with the given name (in the absence of Name_Error). When Start_Search propagates Name_Error or Use_Error, the object Search will have no entries available.
procedure End_Search (Search : in out Search_Type);
Ends the search represented by Search. After a successful call on End_Search, the object Search will have no entries available.
function More_Entries (Search : in Search_Type) return Boolean;
Returns True if more entries are available to be returned by a call to Get_Next_Entry for the specified search object, and False otherwise.
procedure Get_Next_Entry (Search : in out Search_Type;
Directory_Entry : out Directory_Entry_Type);
Returns the next Directory_Entry for the search described by Search that matches the pattern and filter. If no further matches are available, Status_Error is raised. It is implementation defined as to whether the results returned by this subprogram are altered if the contents of the directory are altered while the Search object is valid (for example, by another program). The exception Use_Error is propagated if the external environment does not support continued searching of the directory represented by Search.
procedure Search (
Directory : in String;
Pattern : in String;
Filter : in Filter_Type := (others => True);
Process : not null access procedure (
Directory_Entry : in Directory_Entry_Type))
with Allows_Exit;
Searches in the directory named by Directory for entries matching Pattern and Filter. The subprogram designated by Process is called with each matching entry in turn. Pattern represents a pattern for matching file names. If Pattern is the null string, all items in the directory are matched; otherwise, the interpretation of Pattern is implementation defined. Only items that match Filter will be returned. The exception Name_Error is propagated if the string given by Directory does not identify an existing directory, or if Pattern does not allow the identification of any possible external file or directory. The exception Use_Error is propagated if the external environment does not support the searching of the directory with the given name (in the absence of Name_Error).
function Simple_Name (Directory_Entry : in Directory_Entry_Type)
return String;
Returns the simple external name of the external file (including directories) represented by Directory_Entry. The format of the name returned is implementation defined. The exception Status_Error is propagated if Directory_Entry is invalid.
function Full_Name (Directory_Entry : in Directory_Entry_Type)
return String;
Returns the full external name of the external file (including directories) represented by Directory_Entry. The format of the name returned is implementation defined. The exception Status_Error is propagated if Directory_Entry is invalid.
function Kind (Directory_Entry : in Directory_Entry_Type)
return File_Kind;
Returns the kind of external file represented by Directory_Entry. The exception Status_Error is propagated if Directory_Entry is invalid.
function Size (Directory_Entry : in Directory_Entry_Type)
return File_Size;
Returns the size of the external file represented by Directory_Entry. The size of an external file is the number of stream elements contained in the file. If the external file represented by Directory_Entry is not an ordinary file, the result is implementation defined. The exception Status_Error is propagated if Directory_Entry is invalid. The exception Constraint_Error is propagated if the file size is not a value of type File_Size.
function Modification_Time (Directory_Entry : in Directory_Entry_Type)
return Ada.Calendar.Time;
Returns the time that the external file represented by Directory_Entry was most recently modified. If the external file represented by Directory_Entry is not an ordinary file, the result is implementation defined. The exception Status_Error is propagated if Directory_Entry is invalid. The exception Use_Error is propagated if the external environment does not support reading the modification time of the file represented by Directory_Entry.
Implementation Requirements
123/2For Copy_File, if Source_Name identifies an existing external ordinary file created by a predefined Ada input-output package, and Target_Name and Form can be used in the Create operation of that input-output package with mode Out_File without raising an exception, then Copy_File shall not propagate Use_Error.
Implementation Advice
124/2If other information about a file (such as the owner or creation date) is available in a directory entry, the implementation should provide functions in a child package Directories.Information to retrieve it.
package Ada.Directories.Information
with Global => in out synchronized is
-- System-specific directory information.
-- Version for the Microsoft® Windows® operating system.
124.d/2function Creation_Time (Name : in String) return Ada.Calendar.Time;
124.e/2function Last_Access_Time (Name : in String) return Ada.Calendar.Time;
124.f/2function Is_Read_Only (Name : in String) return Boolean;
124.g/2function Needs_Archiving (Name : in String) return Boolean;
-- This generally means that the file needs to be backed up.
-- The flag is only cleared by backup programs.
124.h/2function Is_Compressed (Name : in String) return Boolean;
124.i/2function Is_Encrypted (Name : in String) return Boolean;
124.j/2function Is_Hidden (Name : in String) return Boolean;
124.k/2function Is_System (Name : in String) return Boolean;
124.l/2function Is_Offline (Name : in String) return Boolean;
124.m/2function Is_Temporary (Name : in String) return Boolean;
124.n/2function Is_Sparse (Name : in String) return Boolean;
124.o/2function Is_Not_Indexed (Name : in String) return Boolean;
124.p/2function Creation_Time (Directory_Entry : in Directory_Entry_Type)
return Ada.Calendar.Time;
124.q/2function Last_Access_Time (Directory_Entry : in Directory_Entry_Type)
return Ada.Calendar.Time;
124.r/2function Is_Read_Only (Directory_Entry : in Directory_Entry_Type) return Boolean;
124.s/2function Needs_Archiving (Directory_Entry : in Directory_Entry_Type) return Boolean;
-- This generally means that the file needs to be backed up.
-- The flag is only cleared by backup programs.
124.t/2function Is_Compressed (Directory_Entry : in Directory_Entry_Type) return Boolean;
124.u/2function Is_Encrypted (Directory_Entry : in Directory_Entry_Type) return Boolean;
124.v/2function Is_Hidden (Directory_Entry : in Directory_Entry_Type) return Boolean;
124.w/2function Is_System (Directory_Entry : in Directory_Entry_Type) return Boolean;
124.x/2function Is_Offline (Directory_Entry : in Directory_Entry_Type) return Boolean;
124.y/2function Is_Temporary (Directory_Entry : in Directory_Entry_Type) return Boolean;
124.z/2function Is_Sparse (Directory_Entry : in Directory_Entry_Type) return Boolean;
124.aa/2function Is_Not_Indexed (Directory_Entry : in Directory_Entry_Type) return Boolean;
124.bb/2-- Additional implementation-defined subprograms allowed here.
end Ada.Directories.Information;
package Ada.Directories.Information
with Global => in out synchronized is
-- System-specific directory information.
-- Unix and similar systems version.
124.ee/2function Last_Access_Time (Name : in String) return Ada.Calendar.Time;
124.ff/2function Last_Status_Change_Time (Name : in String) return Ada.Calendar.Time;
124.gg/2type Permission is
(Others_Execute, Others_Write, Others_Read,
Group_Execute, Group_Write, Group_Read,
Owner_Execute, Owner_Write, Owner_Read,
Set_Group_ID, Set_User_ID);
124.hh/2type Permission_Set_Type is array (Permission) of Boolean;
124.ii/2function Permission_Set (Name : in String) return Permission_Set_Type;
124.jj/2function Owner (Name : in String) return String;
-- Returns the image of the User_Id. If a definition of User_Id
-- is available, an implementation-defined version of Owner
-- returning User_Id should also be defined.
124.kk/3function Group (Name : in String) return String;
-- Returns the image of the Group_Id. If a definition of Group_Id
-- is available, an implementation-defined version of Group
-- returning Group_Id should also be defined.
124.ll/2function Is_Block_Special_File (Name : in String) return Boolean;
124.mm/2function Is_Character_Special_File (Name : in String) return Boolean;
124.nn/2function Is_FIFO (Name : in String) return Boolean;
124.oo/2function Is_Symbolic_Link (Name : in String) return Boolean;
124.pp/2function Is_Socket (Name : in String) return Boolean;
124.qq/2function Last_Access_Time (Directory_Entry : in Directory_Entry_Type)
return Ada.Calendar.Time;
124.rr/2function Last_Status_Change_Time (Directory_Entry : in Directory_Entry_Type)
return Ada.Calendar.Time;
124.ss/2function Permission_Set (Directory_Entry : in Directory_Entry_Type)
return Permission_Set_Type;
124.tt/2function Owner (Directory_Entry : in Directory_Entry_Type) return String;
-- See Owner above.
124.uu/2function Group (Directory_Entry : in Directory_Entry_Type) return String;
-- See Group above.
124.vv/2function Is_Block_Special_File (Directory_Entry : in Directory_Entry_Type)
return Boolean;
124.ww/2function Is_Character_Special_File (Directory_Entry : in Directory_Entry_Type)
return Boolean;
124.xx/2function Is_FIFO (Directory_Entry : in Directory_Entry_Type) return Boolean;
124.yy/2function Is_Symbolic_Link (Directory_Entry : in Directory_Entry_Type)
return Boolean;
124.zz/2function Is_Socket (Directory_Entry : in Directory_Entry_Type) return Boolean;
124.aaa/2-- Additional implementation-defined subprograms allowed here.
end Ada.Directories.Information;
Start_Search and Search should raise Name_Error if Pattern is malformed, but not if it can represent a file in the directory but does not actually do so.
Rename should be supported at least when both New_Name and Old_Name are simple names and New_Name does not identify an existing external file.
begin
Rename (Source, Target);
exception
when Use_Error =>
Copy_File (Source, Target);
Delete (Source);
end;
Extensions to Ada 95
Inconsistencies With Ada 2005
Incompatibilities With Ada 2005
use_clause
, and an entity E with a defining_identifier
of one of the new entities is defined in a package that is also referenced in a use_clause
, the entity E may no longer be use-visible, resulting in errors. This should be rare and is easily fixed if it does occur. Wording Changes from Ada 2005
Wording Changes from Ada 2012
A.16.1 The Package Directories.Hierarchical_File_Names
1/3The library package Directories.Hierarchical_File_Names is an optional package providing operations for file name construction and decomposition for targets with hierarchical file naming.
Static Semantics
2/3If provided, the library package Directories.Hierarchical_File_Names has the following declaration:
package Ada.Directories.Hierarchical_File_Names
with Nonblocking, Global => in out synchronized is
4/3function Is_Simple_Name (Name : in String) return Boolean;
5/3function Is_Root_Directory_Name (Name : in String) return Boolean;
6/3function Is_Parent_Directory_Name (Name : in String) return Boolean;
7/3function Is_Current_Directory_Name (Name : in String) return Boolean;
8/3function Is_Full_Name (Name : in String) return Boolean;
9/3function Is_Relative_Name (Name : in String) return Boolean;
10/3function Simple_Name (Name : in String) return String
renames Ada.Directories.Simple_Name;
11/3function Containing_Directory (Name : in String) return String
renames Ada.Directories.Containing_Directory;
12/3function Initial_Directory (Name : in String) return String;
13/3function Relative_Name (Name : in String) return String;
14/3function Compose (Directory : in String := "";
Relative_Name : in String;
Extension : in String := "") return String;
15/3end Ada.Directories.Hierarchical_File_Names;
16/3In addition to the operations provided in package Directories.Hierarchical_File_Names, the operations in package Directories can be used with hierarchical file names. In particular, functions Full_Name, Base_Name, and Extension provide additional capabilities for hierarchical file names.
function Is_Simple_Name (Name : in String) return Boolean;
Returns True if Name is a simple name, and returns False otherwise.
function Is_Root_Directory_Name (Name : in String) return Boolean;
Returns True if Name is syntactically a root (a directory that cannot be decomposed further), and returns False otherwise.
function Is_Parent_Directory_Name (Name : in String) return Boolean;
Returns True if Name can be used to indicate symbolically the parent directory of any directory, and returns False otherwise.
function Is_Current_Directory_Name (Name : in String) return Boolean;
Returns True if Name can be used to indicate symbolically the directory itself for any directory, and returns False otherwise.
function Is_Full_Name (Name : in String) return Boolean;
Returns True if the leftmost directory part of Name is a root, and returns False otherwise.
function Is_Relative_Name (Name : in String) return Boolean;
Returns True if Name allows the identification of an external file (including directories and special files) but is not a full name, and returns False otherwise.
function Initial_Directory (Name : in String) return String;
Returns the leftmost directory part in Name. [That is, it returns a root directory name (for a full name), or one of a parent directory name, a current directory name, or a simple name (for a relative name).] The exception Name_Error is propagated if the string given as Name does not allow the identification of an external file (including directories and special files).
function Relative_Name (Name : in String) return String;
Returns the entire file name except the Initial_Directory portion. The exception Name_Error is propagated if the string given as Name does not allow the identification of an external file (including directories and special files), or if Name has a single part (this includes if any of Is_Simple_Name, Is_Root_Directory_Name, Is_Parent_Directory_Name, or Is_Current_Directory_Name are True).
function Compose (Directory : in String := "";
Relative_Name : in String;
Extension : in String := "") return String;
Returns the name of the external file with the specified Directory, Relative_Name, and Extension. The exception Name_Error is propagated if the string given as Directory is not the null string and does not allow the identification of a directory, or if Is_Relative_Name (Relative_Name) is False, or if the string given as Extension is not the null string and is not a possible extension, or if Extension is not the null string and Simple_Name (Relative_Name) is not a base name.
The result of Compose is a full name if Is_Full_Name (Directory) is True; result is a relative name otherwise.
For N>1,
Containing_Directory(Rel(N)) = Leftmost Rel(N-1),
Containing_Directory(Full(N)) = Leftmost Full(N-1),
Else if N = 1, raise Use_Error .
For N>1,
Relative_Name(Rel(N)) = Rightmost Rel(N-1),
Relative_Name(Full(N)) = Rightmost Full(N-1),
Else if N = 1, raise Name_Error.
Compose (Directory => Full(N), Relative_Name => Rel(M)) => Full(N+M)
Compose (Directory => Rel(N), Relative_Name => Rel(M)) => Rel(N+M)
Name_Error if Relative_Name is a Full(M).
Implementation Advice
36/3Directories.Hierarchical_File_Names should be provided for systems with hierarchical file naming, and should not be provided on other systems.
Extensions to Ada 2005
A.16.2 The Packages Wide_Directories and Wide_Wide_Directories
1/5The packages Wide_Directories and Wide_Wide_Directories provide operations for manipulating files and directories, and their names.
Static Semantics
2/5The specification of package Wide_Directories is the same as for Directories (including its optional child packages Information and Hierarchical_File_Names), except that each occurrence of String is replaced by Wide_String.
The specification of package Wide_Wide_Directories is the same as for Directories (including its optional child packages Information and Hierarchical_File_Names), except that each occurrence of String is replaced by Wide_Wide_String.