Skip to content

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

instance method

FileTest#directory?

(::path | ::io file_name) -> 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 #chardev? #empty? #blockdev? #executable? also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0