read()
public
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
Show source
static VALUE
dir_read(VALUE dir)
{
struct dir_data *dirp;
struct dirent *dp;
GetDIR(dir, dirp);
errno = 0;
if ((dp = READDIR(dirp->dir, dirp->enc)) != NULL) {
return rb_external_str_new_with_enc(dp->d_name, NAMLEN(dp), dirp->enc);
}
else {
if (errno != 0) rb_sys_fail(0);
return Qnil; /* end of stream */
}
}