Skip to content

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

instance method

Pathname#entries

entries

Return the entries (files and subdirectories) in the directory, each as a Pathname object.

The results contains just the names in the directory, without any trailing slashes or recursive look-up.

Example
pp Pathname.new('/usr/local').entries
#=> [#<Pathname:share>,
#    #<Pathname:lib>,
#    #<Pathname:..>,
#    #<Pathname:include>,
#    #<Pathname:etc>,
#    #<Pathname:bin>,
#    #<Pathname:man>,
#    #<Pathname:games>,
#    #<Pathname:.>,
#    #<Pathname:sbin>,
#    #<Pathname:src>]

The result may contain the current directory #<Pathname:.> and the parent directory #<Pathname:..>.

If you don’t want . and .. and want directories, consider Pathname#children.

See also #empty? #eql? #each_line #executable? also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1