..


Sponsored Links

How Ruby handles folders?

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.pwd

 
To 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}

 

In the same category ...
E-Learning
Ruby and Ruby on Rails (Course) Ruby and Ruby on Rails (Course)
Create software and Web applications with Ruby and RoR. From 39 €.
Sponsored Links