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
file.c
View on GitHub ↗
VALUE
rb_file_directory_p(VALUE obj, VALUE fname)
{
#ifndef S_ISDIR
# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
#endif
struct stat st;
if (rb_stat(fname, &st) < 0) return Qfalse;
if (S_ISDIR(st.st_mode)) return Qtrue;
return Qfalse;
}
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