Changes

Ruby Directory Handling

2 bytes removed, 15:20, 31 March 2009
no edit summary
== Changing Directory in Ruby ==
<google>ADSDAQBOX_FLOW</google>
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 file system from within the Ruby code. Ruby provides a number of useful directory navigation methods in the ''Dir'' class.
First, it is often useful to identify the current directory. This can be done with the ''pwd'' methods method of the Ruby ''Dir'' class:
<tt>
</tt>
Changing the current working directory in Ruby is achieved using the ''chdir'' method of the Ruby ''Dir'' class. This methods method takes the path of the destination directory as an argument:
<tt>
== Directory Listings in Ruby ==
Once we have navigated to the desired directory it is a common requirement to obtain a listing of files contained within that directory. Such a listing can be obtained using the ''entries'' method. The ''entries'' methods method takes as an argument the path of the directory for which a listing is required and returns an array containing the names of the files in that directory:
In the following example we request a listing of the files in the current directory, which is represented by a dot (.).