To rename a file or folder in Ruby you can use the following snippet.

Sample Ruby

begin  
  File.rename("/path/to/oldfile", "/path/to/newfile")  
rescue Exception => e  
  # the exception your way
end 

2 thought on “How to rename a file or folder in Ruby”

Leave a Reply