Ruby way to rename a file

Hi all,

I want to change a file name in a path directly. What is the ruby way to
do that?

For example:

change old_file=“C:/path/a/b/c/old.html”

to new file=“C:/path/a/b/c/new.html”

Thanks,

You could use File.rename(old_file, new_file)
There’s File.path(old_file) if you want to just get the path and then
add your new filename.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs