Changes

Jump to: navigation, search

Ruby Directory Handling

7 bytes removed, 13:20, 1 December 2007
no edit summary
When a Ruby application is launched it is usually done from a particular directory. Often it is necessary to navigate to a different directory somewhere on the filesystem from within the Ruby code. Ruby provides a number of useful directory navigation methods in the ''Dir'' class.
First, it is often usefl useful to identify the current directory. This can be done with the ''pwd'' methods of the Ruby ''Dir'' class:
<pre>
== Creating New Directories ==
Directory creation in Ruby is handled by the ''mkdir'' method of the ''Dir'' class. This method takes as its argument the path of the new directory. this This can either be a full path to the directory, or a relative path based on the current working directory:
<pre>
<pre>
Dir.entries(".")
=> ["techotopia_stats.jpg", "toolButton_ISTtoolButton.png", ".", "..", "techotopia_stats_since_start.jpg", "music_728x90_1.jpg", "music_468x60_a.jpg", "Fedora_essentials.jpg"]
</pre>
dirListing.each { |file| puts file }
techotopia_stats.jpg
toolButton_ISTtoolButton.png
.
..

Navigation menu