Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   




RUBY - DELETING OR RENAMING FILES


Deleting a File


Deleting a file is quite simple in Ruby.


We can use the delete() method to delete a file.


Example :



File.delete("myfirstfile.txt")


Output :




And, the file myfirstfile.txt is deleted from the current directory.


Renaming a File


We can use the rename() method to delete a file.


Let's say, we have a file called myfirstfile.txt and we want to rename it to newfirstfile.txt.


Example :



File.rename("myfirstfile.txt","newfirstfile.txt")


Output :




Now, if you see open your folder, you can find the file, myfirstfile.txt got renamed to newfirstfile.txt.