End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Dir#read
dir.read → string or nil
dir.c
View on GitHub ↗
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 {
int e = errno;
if (e != 0) rb_syserr_fail(e, 0);
return Qnil; /* end of stream */
}
}
Reads the next entry from dir and returns it as a string. Returns nil at the end of the stream.
Example
d = Dir.new("testdir") d.read #=> "." d.read #=> ".." d.read #=> "config.h"