public Method

Dir.read

dir.read  string or nil

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

d = Dir.new("testdir")
d.read   #=> "."
d.read   #=> ".."
d.read   #=> "config.h"

Source Code

/*
*  call-seq:
*     dir.read => string or nil
*
*  Reads the next entry from <em>dir</em> and returns it as a string.
*  Returns <code>nil</code> at the end of the stream.
*
*     d = Dir.new("testdir")
*     d.read   #=> "."
*     d.read   #=> ".."
*     d.read   #=> "config.h"
*/
static VALUE
dir_read(dir)
   VALUE dir;
{
   struct dir_data *dirp;
   struct dirent *dp;

   GetDIR(dir, dirp);
   errno = 0;
   dp = readdir(dirp->dir);
   if (dp) {
       return rb_tainted_str_new(dp->d_name, NAMLEN(dp));
   }
   else if (errno == 0) {      /* end of stream */
       return Qnil;
   }
   else {
       rb_sys_fail(0);
   }
   return Qnil;                /* not reached */
}
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.