Ada.Directories.Containing_Directory Example

with Ada.Text_IO;
with Ada.Directories;
 
procedure aDir is
   package IO renames Ada.Text_IO;
   package D renames Ada.Directories;
 
begin
   IO.Put ("Starting default directory: ");
   IO.Put_Line (Item => D.Current_Directory);
 
   IO.Put_Line (Item => D.Containing_Directory (Name => "foo"));
   IO.Put_Line (Item => D.Containing_Directory (Name => "foo/bar"));
   IO.Put_Line (Item => D.Containing_Directory (Name => "/home/thomas/stuff"));
 
   declare
   begin
      IO.Put_Line (Item => D.Containing_Directory (Name => ""));
      --  Malformed Name parameter
   exception
      when D.Name_Error =>
         IO.Put_Line (Item => "Name_Error raised. Malformed Name.");
   end;
 
   declare
   begin
      IO.Put_Line (Item => D.Containing_Directory (Name => "/"));
      --  No parent directory
   exception
      when D.Use_Error =>
         IO.Put_Line (Item => "Use_Error raised. No containing directory.");
   end;
end aDir;

Go back


Navigation