Ruby Dir Functions

EditRocket provides the following information on Dir functions in the Ruby source code builder.

chdir( [ string] ) - Changes the current working directory of the process to the given string. When called without an argument, changes the directory to the value of the environment variable HOME, or LOGDIR. SystemCallError (probably Errno::ENOENT) if the target directory does not exist.

chroot( string ) - Changes this process's idea of the file system root. Only a privileged process may make this call. Not available on all platforms. On Unix systems, see chroot(2) for more information.

close - Closes the directory stream. Any further attempts to access dir will raise an IOError.

delete( string ) - Deletes the named directory. Raises a subclass of SystemCallError if the directory isn't empty.

each - Calls the block once for each entry in this directory, passing the filename of each entry as a parameter to the block.

entries( dirname ) - Returns an array containing all of the filenames in the given directory. Will raise a SystemCallError if the named directory doesn't exist.

foreach( dirname ) - Calls the block once for each entry in the named directory, passing the filename of each entry as a parameter to the block.

getwd - Returns the path to the current working directory of this process as a string.

glob( pattern, [flags] ) - Returns the filenames found by expanding pattern which is an Array of the patterns or the pattern String, either as an array or as parameters to the block. Note that this pattern is not a regexp (it's closer to a shell glob). See File::fnmatch for the meaning of the flags parameter. Note that case sensitivity depends on your system (so File::FNM_CASEFOLD is ignored)

mkdir( string [, integer] ) - Makes a new directory named by string, with permissions specified by the optional parameter anInteger. The permissions may be modified by the value of File::umask, and are ignored on NT. Raises a SystemCallError if the directory cannot be created. See also the discussion of permissions in the class documentation for File.

new( string ) - Returns a new directory object for the named directory.

open( string ) - With no block, open is a synonym for Dir::new. If a block is present, it is passed aDir as a parameter. The directory is closed at the end of the block, and Dir::open returns the value of the block.

path - Returns the path parameter passed to dir's constructor.

pos= dir.pos( integer ) - Synonym for Dir#seek, but returns the position parameter.

pos - Returns the current position in dir. See also Dir#seek.

pwd - Returns the path to the current working directory of this process as a string.

read - Reads the next entry from dir and returns it as a string. Returns nil at the end of the stream.

rewind - Repositions dir to the first entry.

rmdir( string ) - Deletes the named directory. Raises a subclass of SystemCallError if the directory isn't empty.

seek( integer ) - Seeks to a particular location in dir. integer must be a value returned by Dir#tell.

tell - Returns the current position in dir. See also Dir#seek.

tmpdir() - Returns the operating system's temporary file path.

unlink( string ) - Deletes the named directory. Raises a subclass of SystemCallError if the directory isn't empty.