Ada.Directories.Delete_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);
 
   D.Set_Directory (Directory => "/home/thomas/wiki_examples/aDir");
   IO.Put ("New default directory: ");
   IO.Put_Line (Item => D.Current_Directory);
 
   D.Create_Directory (New_Directory => "some_dir");
   if D.Exists (Name => "some_dir") then
      IO.Put_Line ("some_dir exists.");
   end if;
   D.Delete_Directory (Directory => "some_dir");
 
   D.Create_Directory (New_Directory => "some_dir2");
   if D.Exists (Name => "some_dir2") then
      IO.Put_Line ("some_dir2 exists.");
   end if;
   D.Delete_Directory (Directory => "/home/thomas/wiki_examples/aDir/some_dir2");
end Adir;
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);
 
   Delete_Non_Existing :
   declare
   begin
      D.Delete_Directory (Directory => "does_not_exist");  
   exception
      when D.Name_Error =>
         IO.Put_Line (Item => "Directory not found.");
   end Delete_Non_Existing;
 
   Delete_With_Contents :
   declare  
   begin
      D.Delete_Directory (Directory => "dir_with_contents");    
   exception
      when D.Use_Error =>
         IO.Put_Line (Item => "Cannot delete non-empty directory.");
   end Delete_With_Contents;
end aDir;

Go back


Navigation