Skip to content

End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

class method

Dir.children

Dir.children( dirname ) → array
Dir.children( dirname, encoding: enc ) → array

Returns an array containing all of the filenames except for “.” and “..” in the given directory. Will raise a SystemCallError if the named directory doesn’t exist.

The optional encoding keyword argument specifies the encoding of the directory. If not specified, the filesystem encoding is used.

Example
Dir.children("testdir")   #=> ["config.h", "main.rb"]
See also #children .chdir .chroot .[] also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0