Method: Dir#read
- Defined in:
- dir.c
#read ⇒ String?
Reads and returns the next entry name from self
; returns nil
if at end-of-stream; see Dir As Stream-Like:
dir = Dir.new('example')
dir.read # => "."
dir.read # => ".."
dir.read # => "config.h"
890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 |
# File 'dir.c', line 890
static VALUE
dir_read(VALUE dir)
{
struct dir_data *dirp;
struct dirent *dp;
GetDIR(dir, dirp);
rb_errno_set(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 */
}
}
|