Skip to content

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

instance method

Pathname#mkpath

() -> self
mkpath(mode: nil) → self

Creates a directory at the path in self; creates intermediate directories as needed:

Example
pn = Pathname('foo/bar/baz')
pn.directory? # => false
pn.mkpath     # Creates directories 'foo', 'foo/bar', 'foo/bar/baz'.
pn.directory? # => true
pn.rmtree     # Clean up.

When mode is given, directories are created with those permissions; see File Permissions. The permissions for already-existing directories are not changed.

See also #mkdir #mountpoint? #make_symlink #mtime also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0