How to rename a file or folder in Ruby

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 

Please Share us:
Please rate this snippet

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

Leave a Reply