Skip to content

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

class method

Dir.entries

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

Returns an array containing all of the filenames 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.entries("testdir")   #=> [".", "..", "config.h", "main.rb"]
See also .empty? .exist? .each_child .foreach also in 4.1 · 4.0 · 3.4 · 3.3 · 3.1 · 3.0