Ada.Directories.Rename Example

with Ada.Text_IO;
with Ada.Directories;
 
procedure aDir is
   package IO renames Ada.Text_IO;
   package D renames Ada.Directories;
 
   procedure Do_We_Exist (A_Name : String) is
   begin
      if D.Exists (Name => A_Name) then
         IO.Put_Line (Item => "Yes, " & A_Name & " exists");
      else 
         IO.Put_Line (Item => "No, " & A_Name & " does not exist");
      end if;
   end Do_We_Exist;
begin
   IO.Put ("Starting default directory: ");
   IO.Put_Line (Item => D.Current_Directory);
 
   Do_We_Exist (A_Name => "some_new_dir"); 
   Do_We_Exist (A_Name => "some_new_file");
 
   D.Rename (Old_Name => "some_dir",
             New_Name => "some_new_dir");
   D.Rename (Old_Name => "some_file",
             New_Name => "some_new_file");
 
   Do_We_Exist (A_Name => "some_new_dir"); 
   Do_We_Exist (A_Name => "some_new_file");
 
   D.Rename (Old_Name => "some_new_dir",
             New_Name => "some_dir");
   D.Rename (Old_Name => "some_new_file",
             New_Name => "some_file");
end aDir;

Go back


Navigation