Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
class method
File.file?
(::path | ::IO file) -> bool
File.file?(object) → true or false
file.c
View on GitHub ↗
static VALUE
rb_file_file_p(VALUE obj, VALUE fname)
{
struct stat st;
if (rb_stat(fname, &st) < 0) return Qfalse;
return RBOOL(S_ISREG(st.st_mode));
}
Returns whether the given object, a string path or IO object, represents a filesystem entry that exists and is a regular file; see File.ftype:
Example
File.file?('/etc/passwd') # => true File.file?('/etc') # => false File.file?($stdin) # => false File.file?('nosuch') # => false