..
Ruby offers a special class for managing folders: Dir , the class provides the methods necessary for operations such as notification of the current directory:
# Know the current directory Dir.pwdTo create a new folder:
# Create a new folder
Dir.mkdir ('nuova_cartella')
To move from the current folder to a new folder:
# Change the current folder
Dir.chdir ('nuova_cartella')
You can read the contents of a folder through a simple loop:
# Read the contents of a folder
Dir.foreach ('folder_name') {| file | puts file}
| |
Ruby and Ruby on Rails (Course)
Create software and Web applications with Ruby and RoR. From 39 €. |