Skip to content

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

instance method

Dir#path

() -> ::String?
path → string or nil

If self was created with a string path, returns that path:

Example
dirpath = 'doc/tmp'
Dir.mkdir(dirpath)
dir = Dir.new(dirpath)
dir.path # => "../ruby/doc/syntax"

The path remains even when the directory is removed:

Example
Dir.rmdir(dirpath)
dir.path # => "../ruby/doc/syntax"

If self was created with a file descriptor, returns nil:

Example
dir0 = Dir.new('.')
fd = dir0.fileno # => 8
dir1 = Dir.for_fd(fd)
dir1.path        # => nil
See also #inspect #pos #fileno #pos= also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0