Skip to content

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

class method

File.directory?

(::path | ::IO path) -> bool
File.directory?(object) → true or false

Returns whether the given object represents a directory; object may be a string path or an IO object:

Example
File.directory?('/etc')        # => true
File.directory?('/etc/passwd') # => false
File.directory?($stdin)        # => false
File.directory?('nosuch')      # => false
See also .delete .dirname .ctime .empty? also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0