Skip to content
class method

Dir.entries

(::path dirname, ?encoding: ::encoding?) -> ::Array[::String]
Dir.entries(dirname, encoding: 'UTF-8') → array

Returns an array of the entry names in the directory at dirpath; sets the given encoding onto each returned entry name:

Example
Dir.entries('/example') # => ["config.h", "lib", "main.rb", "..", "."]
Dir.entries('/example').first.encoding
# => #<Encoding:UTF-8>
Dir.entries('/example', encoding: 'US-ASCII').first.encoding
# => #<Encoding:US-ASCII>

See String Encoding.

Raises an exception if the directory does not exist.

See also .empty? .exist? .each_child .fchdir also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0