How do I rename a directory in Ruby?
I see how to rename individual files, but not folders.
Use the ren or rename command to rename the directory. Because you cannot have a file and directory of the same name, you don't need to worry about mistakenly renaming a file instead of a directory. The only exception is if you're using wild characters.
To rename any file or folder, use git mv command which takes two arguments. The first argument is the source and the second is the destination. We can easily rename any file using the git command and the new name will be assigned to that file. We can rename the file using GitHub or the command line.
To rename files and folders in Windows 11 using File Explorer, select the file or folder to rename within the File Explorer window. Then click the “Rename” button in the Ribbon at the top of the window. Doing this then highlights the name of the currently selected file or folder and places a thin border around it.
FileUtils.mv old_name, new_name
Check the docs for more info
File.rename
will let you rename directories:
File.rename './my-directory', './my-renamed-directory'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With