Skip to content

Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →

class method

Dir.mkdir

(::path dirname, ?::int permissions) -> 0
Dir.mkdir(dirpath, permissions = 0775) → 0

Creates a directory in the underlying file system at dirpath with the given permissions; returns zero:

Example
Dir.mkdir('foo')
File.stat(Dir.new('foo')).mode.to_s(8)[1..4] # => "0755"
Dir.mkdir('bar', 0644)
File.stat(Dir.new('bar')).mode.to_s(8)[1..4] # => "0644"

See File Permissions. Note that argument permissions is ignored on Windows.

See also .home .mktmpdir .glob .new also in 4.1 · 4.0 · 3.3 · 3.2 · 3.1 · 3.0