Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

class method

Dir.glob

(::array[::path] | ::path pattern, ?::int flags, ?base: ::path?, ?sort: bool) -> ::Array[::String]
(::array[::path] | ::path pattern, ?::int flags, ?base: ::path?, ?sort: bool) { (::String pathname) -> void } -> nil
Dir.glob(patterns, flags: 0, base: '.', sort: true) → array_of_entries
Dir.glob(patterns, flags: 0, base: '.', sort: true) {|entry_name| ... } → nil

Returns an array of filesystem entries; see Filename Globbing.

With a block given, calls the block with each of the selected entry names and returns nil:

Example
Dir.glob('*.rb') {|entry_name| puts entry_name } # => nil

Ruby version changes

  1. 4.1
    • Dir.glob supports ***/ for recursive matching that follows directory symbolic links, stopping at links to ancestor directories. [Feature #17548]

  2. 3.0
See also .getwd .home .for_fd .mkdir also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0