Skip to content
class method

Dir.new

(::path dir, ?encoding: ::encoding?) -> ::Dir
Dir.new(dirpath) → dir
Dir.new(dirpath, encoding: nil) → dir

Returns a new Dir object for the directory at dirpath:

Example
Dir.new('.') # => #<Dir:.>

The value given with optional keyword argument encoding specifies the encoding for the directory entry names; if nil (the default), the file system’s encoding is used:

Example
Dir.new('.').read.encoding                       # => #<Encoding:UTF-8>
Dir.new('.', encoding: Encoding::US_ASCI).read.encoding # => #<Encoding:US-ASCII>
See also .mktmpdir .open .mkdir .pwd also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0